A good argument in favour of python :-) On 17/05/06, Derek Smithies <[EMAIL PROTECTED]> wrote:
Hi, Ok, threshold of pain reached, my turn.On Wed, 17 May 2006, Wesley Parish wrote: > Quoting Wesley Parish <[EMAIL PROTECTED]>: > > Quoting Steve Holdoway <[EMAIL PROTECTED]>: > > > Rex Johnston <[EMAIL PROTECTED]> wrote: > > > > Dale DuRose wrote: you will see many many guides as to the best code, but few explain why. Perhaps if they did explain why, it would become clear what is reasonable, what is not. There are two ideas that are crucial to get, and once you get them, decisions on the ideal code style become simpler. #compilers now are really clever, and will generate awesomly good code. #Code spends more time in the review/update/debug stage than in the writing stage. Let me explain. constructs such as b[i] = i++; are indeed valid, and the compiler will make a reasonable go at compiling it. However, the meaning is not immediately clear. It is better to write it as b[i] = i; i++; The compiler is smart enough to realise you mean the upper expression, and will make that optimisation for you. If the compiler is not smart enough to make this optimisation, you need a better compiler. Similarily, in the for loop construct for(int i = 4; i ; i--) { do_something; } is legally valid. However, if you had said: for(int i = 4; i > 0; i--) { do_something; } surely the compiler would have realised that ;i > 0; is the same as ;i ; and generated the same code? I would argue that the second is slightly (very slightly) clearer Here is the first point:: The compiler is usually smart enough to do the right thing - using those 1980's C tricks like above were written for the poor compilers they had. We now have much better compilers. We can now write code that is more readable to the eye, yet runs just as fast. On the issues of braces at the end of a for statement. On this topic, much ink/emails/electrons have been spilt to no forward gain. yes, using for(;;) { } everywhere does use up an extra line of screen space. It does eliminate the mistake of adding a line to the for loop that is not looped over. However, with a decent indenting editor (my favourite is emacs) such mistakes are quickly caught. yes, the extra brace does help break the method up into smaller groups, which can help in getting an overview of the operation of one method. yes, using for(;;) do_something; is far more succinct and shorter. Well, yes, but you do not follow this arguement to its logical conclusion. for(;;) do_somehting; is far more succinct and shorter. and on the topic of shortness, I suppose I should make my signature -- Derek Smithies Ph.D. Any fool can write code that IndraNet Technologies Ltd. a computer can understand. Email: [EMAIL PROTECTED] Good programmers write code ph +64 3 365 6485 that humans can understand. Web: http://www.indranet-technologies.com/ Martin Fowler which is far more succinct, and real short. Anyone manage to read it in under 4 seconds? yep, and this is point 2. You can have succinctness, yes, but lets have readability. Since we put our code in the repair/update phases for longer than the writing phases, lets get the readability much better. Derek.
