[Tutor] programming style question:
Alan Gauld
alan.gauld@blueyonder.co.uk
Wed May 7 03:48:02 2003
>>while 1:
>> do_lots_of_things_here()
>> if (condition):
>> break
>
>I see no problem with using this type of construct, in fact, I
believe
>it is pretty common to see this sort of thing in Python code.
Its common in Python but not at all common in Pascal.
> ...following the conventions used by programmers before me.
> Consistency is usually better than correctness,
This is the main thing. Consistency within code is really important.
Wen you visually scan a long listing its much easirer if all the code
uses the same indent level, the same placing of block markers etc.
For example, old Pascal code often uses this style:
for n = 1 to 10 do
begin
{ something here}
end
OR
for n = 1 to 10 do
begin
{ do something}
end
Wheras research has shown that a better style from a cognitive
point of view is:
for n = 1 to 10 do begin
{do something}
end
OR (the most Pythonic version!)
for n = 1 to 10 do
begin
{do something}
end
But if maintining old code it would be worse to try to insert
new code with one of the latter styles into code using one of
the first 2 stuyles - that would just be confusing.
OTOH on a new project it would be best to adopt one of the
latter 2 styles for the real cognitive benefits they bring.
Alan G.