Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Yoda coding styles
Message
 
À
21/04/2006 09:47:35
Mike Yearwood
Toronto, Ontario, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01115355
Message ID:
01116539
Vues:
12
I've argued for a long time that we should code more like we write (and read and speak) because it works *with* our brain instead of against it. Therefore I've never liked Hungarian Notation, prefering CustNumStr over cCustNum or InvoicesCursor over curInvoices. HN makes code harder to read and is a poor solution overall (I do prefix controls - thisform.cntButtons.cmdPrint, for instance). I read an article about HN awhile back and the author claimed HN was becoming "persona nongrata" at Microsoft - that heartened me.

Indentation and code alignment is very helpful, though I'll agree it can be taken too far. One thing it does for me is to help me spot mistakes and have them stand out. Another thing that is good is standard spacing. SomeVar=SomeOtherVar+(round(MyVar,2)*3) is just harder to sort out than SomeVar = SomeOtherVar + (round(MyVar, 2) * 3). And vertical whitespace is good, too. Take some code all crammed together both vertically and horizontally and it's just harder to read. I look at that code and I start out with a negative attitude. Clean code with good spacing is just more inviting.

Recently I was thinking about what I learned about coding from typesetting and design (a little sidetrack in the late college years). One thing is good use of white space, as mentioned. Another is that ALL CAPS ARE HARD TO READ AND MAKE THE EYES TIRED AFTER AWHILE. ADDTIONALLY, ALL CAPS DOES NOT GIVE YOUR BRAIN THE SUBTLE CLUES ABOUT UPCOMING WORDS VIA THE ASCENDERS AND DESCENDERS THAT ARE A PART OF LOWERCASE LETTERS. SO I TEND TO USE LOWERCASE FOR VFP COMMANDS AND MIXED CASE FOR MY VARIABLE NAMES IN ORDER TO IMPROVE READABILITY.

One guy - in the UT perhaps - told me HN increased understandability (my word, can't remember his, but that was the gist). Well, I say you *read* code first - often when you're looking for a section of code that pertains to a mod you need to make - and so readability comes first. Then, after you've found the pertinent code, understandability is important. But HN decreases it, IMHO.

Oh well, my two cents. It's an interesting subject. I hope no one gets into flame wars over it. It can be one of those religious things, you know.

Russell Campbell

>>>Everytime I see someone else's code I'm left scratching my head.
>>>
>>>Take this line of code:
>>>
>>>Index Tag shiprate On province+Allt(city) Uniq
>>>
>>>
>>>Besides the data modelling no-no of province and city in a table - permitting various incorrect spellings of province and city and impossible combinations of non-existant cities/provinces, and the questionable practice of having multiple shiprates per city+prov in the table only to ignore any but the first one, the code is written as if by Yoda.
>>>
>>>The help clearly shows
>>>
>>>INDEX ON eExpression TO IDXFileName | TAG TagName [BINARY]
>>> [COLLATE cCollateSequence] [OF CDXFileName] [FOR lExpression]
>>> [COMPACT] [ASCENDING | DESCENDING] [UNIQUE | CANDIDATE] [ADDITIVE]
>>>
>>>So while that line of yodacode works, it throws me for a loop. So I hereby request that we coin the term yodacode to apply to any yoda-like programmers.
>>
>>While I usually code the other way (in the order stated in the manual), the coding style can indeed be justified (in certain circumstances), as follows.
>>
>>The TAG has a maximum length of 10 characters, whereas the index key has a rather variable length.
>>
>>Therefore, in the case you have several INDEX statements one after the other, it is much easier to align your code (having the index tags one below the other, and the index expressions one below the other).
>
>
>
>                                                           Sorry.
>                                                I don't buy that.
>           I've seen code-alignment taken to ridiculous extremes.
>           We are taught to read (English anyways) in paragraphs.
>Why must coders always try to align parts of different sentences?
>                                   This isn't COBOL or Assembler.
>
>Indenting IF and DO CASE and DO WHILE is helpful, as is breaking text into sentences, paragraphs and chapters.
>
>Look how cleverly I aligned all the punctuation! By the way, there were no other index commands being aligned with this one. Some people need to unlearn what they have learned.
eCost.com continues to rip people off
Check their rating at ResellerRatings.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform