Code Snippets

Rhodri James rhodri at kynesim.co.uk
Thu Nov 2 08:18:41 EDT 2017


On 01/11/17 18:57, Stefan Ram wrote:
> Ned Batchelder <ned at nedbatchelder.com> writes:
>> You should not optimize for the shortest time to paste a line of code.Â
>> You should take time and care writing your code, so that it reads best
>> and runs best.  If you needed another os function, would you have two
>> __import__("os") in your code? Ugh.
> 
>    I make a distinction between two kinds of code:
> 
>    1.) Quick-and-dirty code (rapid prototyping)
> 
>    One just wants to find out something using Python code.
>    The code might be written into the Shell and not be saved,
>    or only be saved temporarily. For example, what the sum of
>    5412 and 2141 is, or whether an idea for a program code
>    works at all.
> 
>    The snippets are also intended for such code.
> 
>    2.) Library-grade code
> 
>    This is code that might be around for a longer time and
>    might be maintained in the future. It even is possible that
>    it will become part of a library.
> 
>    It is possible that qnd-code might evolve into lg-code.
>    In this case, it is still possible to remove all »__imports__«.
> 
>    Your comments might apply more to lg-code than to qnd-code.

The bad thing here is that you are training yourself in a coding style 
(quick and dirty) that ought to be rejected in any code that isn't 
completely ephemeral.  And in my experience, most "throw-away" code 
isn't thrown away.

-- 
Rhodri James *-* Kynesim Ltd



More information about the Python-list mailing list