November 11th, 2013, 04:29 AM
Hey, I have a general "best practises" question for you guys.
I'm playing around a bit, making unittests and python snippets for later use, partly because I want to learn and partly because they might come in handy later.
So I took an old function I've made, which adds two tuples of the same length together, wrote some tests for it. Then figured out I wanted to be able to add tuples of diffrent lengths together, then figured out i wanted to add lists and tuples together, then I thought why must it be adding, couldn't it be multiplicating if I pass a variable to it. and so on and so on.
So my question is: Where is the magic border between simple and complex? I've heard in several talks on youtube that functions should only do one thing and be as simple as they can be. When am I crossing the line?
November 11th, 2013, 09:32 AM
Writing many code snippets helps me learn a computer language and develop techniques that work for me to "get the job done".
The notion that a great many of these snippets will be useful later, and easier to find and adapt to current requirement than to rewrite hasn't worked well.
Have you written a catalog indexing system?
As a FORTRAN programmer using 72 character fixed width source format I adhered to short code lines. For a couple decades now emacs presents 150 characters without wrapping (194 on monitor of the day, a 14" diagonal in a quite readable font). A 72 character rule is gone. FORTRAN still limits me to 132 characters.
Splitting tasks into reusable general purpose chunks is the genius of unix, the legacy of Ritchie, Thompson, Kernighan, undoubtedly others. I do not know the historical roots of the unix pipeline. Or were tr, sed, all the core utilities invented by these guys?
[/code] are essential for python code and Makefiles!
November 11th, 2013, 10:38 AM
No, I haven't written a catalog index system, I dont really have anough snippets for that yet. Currently reading through all python I've written and checking if there's any useful functions I could use or derive ideas from.
So I'm just sorting them in categories in a document for now, like "String Handling" and such.
I use 80 characters myself, I'm used to it and it just works for me. I feel it makes my code easier to read(for the most part).