• (cs)

    I think this is the first time I've seen a WTF hit the front page of Digg... awesome.

  • (cs)

    I really hate it when coders do have the opinion that there is such a thing like code coding that wouldn't require comments, instructions or documents. In most of the cases, it turns out only 1 or 2 people actually understands that code, and for others it is still a mystery.

    Once I was as project manager in charge of a big development project working with 15 developers. When discussing the way we would document our code, one smart-ass had the opinion that he chooses his java objectnames en methods in such a way that no documentation was needed. He was really pissed off when I made him head of the testing team and also responsible for any peer-reviewing. I really hopes he learned something from it.

  • Henry Troup (unregistered) in reply to AdT

    Until, of course, you find the complex algorithm that uses that variable and

    defaultSizedIntegerVariableIndexingIntoEmployeesVectorWhichIsAVectorOfEmployeeRecordsEachOfWhichContainsPersonalInformationSuchAsFirstNameLastNameDateOfBirthAndRegisteredResidenceAsWellAsProfessionalInformationSuchAsJobTitleAndSalary_ThisVariableWasAddedByChiefSoftwareArchitectJohnDoeOnTheEveningOfWednesdayNovember12th2008RightAfterDinner

    and also

    defaultSizedIntegerVariableIndexingIntoEmployeesVectorWhichIsAVectorOfEmployeeRecordsEachOfWhichContainsPersonalInformationSuchAsFirstNameLastNameDateOfBirthAndRegisteredResidenceAsWellAsProfessionalInformationSuchAsJobTitleAndSalary_ThisVariableWasAddedByChiefSoftwareArchitectJohnDoeOnTheEveningOfWednesdayNovember13th2008RightBeforeDinner

    (I think I had to debug that code once - on a 40 column screen.)

  • Henry Troup (unregistered) in reply to Code Slave

    Try 6 character uniqueness. That was hard to live with at times. Circa 1980, iirc

  • Peter (unregistered)

    I am a great fan of certain aspects of extreme programming, but this is exactly the reason, why we document in our code like this.

    case InventoryIntegrationDirection.DoTheSameChangeInShop: //Do The Same Change In Shop DoChangeShop(GetChangedDataFromInventory(mLastSynchDate)); break;

    case InventoryIntegrationDirection.DoTheSameChangeInInventory: //Do The Same Change In Inventory DoChangeInventory(GetChangedDataFromShop(mLastSynchDate)); break;

    case InventoryIntegrationDirection.DoTheSameChangeInShopThenDoTheSameChangeInInventoryForNotChangedDataInInventory: //Do The Same Change In Shop Then Do The Same Change In Inventory For Not ChangedData In Inventory( DoChangeShop_Inventory( GetChangedDataFromInventory(mLastSynchDate), GetChangedDataFromShop(mLastSynchDate)); break;

    case InventoryIntegrationDirection.DoTheSameChangeInInventoryThenDoTheSameChangeInShopForNotChangedData: //Do The Same Change In Inventory Then Do The Same Change In Shop For Not Changed Data( DoChangeInventory_Shop(GetChangedDataFromShop(mLastSynchDate), GetChangedDataFromInventory(mLastSynchDate)); break;

    The nice green colour of the comments makes it clear in a second.

    The Problem with Bens's boss is that he never read Kant: You should not blindly obey authority (Beck & Co) but think for yourself.

  • x (unregistered)
    DoTheSameChangeInShopThenDoTheSameChangeInInventoryForNotChangedDataInInventory

    That's perhaps too long. DoTheSameChangeInShopAndInventory or DoTheSameChangeInShopAndUnchangedInventoryData would be ok, however. It's certainly much better than

    samechange3 //long explanation, only at definition
    

    This guy's code IS self documenting. It's not a wtf. He just should be more terse, when possible. Long variable names > short names with comments.

    P.S. I assume that the meaning of "do the same change" is clear, given the code's context.

  • Georgem (unregistered)

    The real WTF is his dubious use of control flow. The naming convention itself is fine, but if he'd read Fowler's Refactoring - especially the bit about "replace conditional with polymorphism" - he'd probably have eliminated the need for such long constant names, too. Self-documenting code like this is wonderful for many reasons, one of which is that it eliminates the need for comments. The other is that it provides a nice metric for when your design stinks. Can't thinkn of a meaningful method name that isn't 50 characters long? The method's probably too busy.

  • Georgem (unregistered) in reply to Georgem

    That should be "another", not "the other"

  • Georgem (unregistered) in reply to AdT
    AdT:
    Integer variables used in for loops often have horribly indescript names such as "i". Better names would be something like "defaultSizedIntegerVariableIndexingIntoEmployeesVectorWhichIsAVectorOfEmployeeRecordsEachOfWhichContainsPersonalInformationSuchAsFirstNameLastNameDateOfBirthAndRegisteredResidenceAsWellAsProfessionalInformationSuchAsJobTitleAndSalary_ThisVariableWasAddedByChiefSoftwareArchitectJohnDoeOnTheEveningOfWednesdayNovember12th2008RightBeforeDinner".

    Even version control can be made obsolete by self-documenting variable names. Think of "longSizedInteger...FormerlyKnownAsDefaultSizedInteger..."

    Sarcasm detected, but loop counters and such are exempt from descriptive names. Anybody who can't tell a loop index has no business trying to maintain code anyway

  • Troy (unregistered) in reply to AdT

    That will make for a nice readable for loop too: for(int defaultSizedIntegerVariableIndexingIntoEmployeesVectorWhichIsAVectorOfEmployeeRecordsEachOfWhichContainsPersonalInformationSuchAsFirstNameLastNameDateOfBirthAndRegisteredResidenceAsWellAsProfessionalInformationSuchAsJobTitleAndSalary_ThisVariableWasAddedByChiefSoftwareArchitectJohnDoeOnTheEveningOfWednesdayNovember12th2008RightBeforeDinner; defaultSizedIntegerVariableIndexingIntoEmployeesVectorWhichIsAVectorOfEmployeeRecordsEachOfWhichContainsPersonalInformationSuchAsFirstNameLastNameDateOfBirthAndRegisteredResidenceAsWellAsProfessionalInformationSuchAsJobTitleAndSalary_ThisVariableWasAddedByChiefSoftwareArchitectJohnDoeOnTheEveningOfWednesdayNovember12th2008RightBeforeDinner < EmployeesVectorWhichIsAVectorOfEmployeeRecordsEachOfWhichContainsPersonalInformationSuchAsFirstNameLastNameDateOfBirthAndRegisteredResidenceAsWellAsProfessionalInformationSuchAsJobTitleAndSalary.size(); ++defaultSizedIntegerVariableIndexingIntoEmployeesVectorWhichIsAVectorOfEmployeeRecordsEachOfWhichContainsPersonalInformationSuchAsFirstNameLastNameDateOfBirthAndRegisteredResidenceAsWellAsProfessionalInformationSuchAsJobTitleAndSalary_ThisVariableWasAddedByChiefSoftwareArchitectJohnDoeOnTheEveningOfWednesdayNovember12th2008RightBeforeDinner)

  • Georgem (unregistered) in reply to Troy
    Troy:
    That will make for a nice readable for loop too: for(int defaultSizedIntegerVariableIndexingIntoEmployeesVectorWhichIsAVectorOfEmployeeRecordsEachOfWhichContainsPersonalInformationSuchAsFirstNameLastNameDateOfBirthAndRegisteredResidenceAsWellAsProfessionalInformationSuchAsJobTitleAndSalary_ThisVariableWasAddedByChiefSoftwareArchitectJohnDoeOnTheEveningOfWednesdayNovember12th2008RightBeforeDinner; defaultSizedIntegerVariableIndexingIntoEmployeesVectorWhichIsAVectorOfEmployeeRecordsEachOfWhichContainsPersonalInformationSuchAsFirstNameLastNameDateOfBirthAndRegisteredResidenceAsWellAsProfessionalInformationSuchAsJobTitleAndSalary_ThisVariableWasAddedByChiefSoftwareArchitectJohnDoeOnTheEveningOfWednesdayNovember12th2008RightBeforeDinner < EmployeesVectorWhichIsAVectorOfEmployeeRecordsEachOfWhichContainsPersonalInformationSuchAsFirstNameLastNameDateOfBirthAndRegisteredResidenceAsWellAsProfessionalInformationSuchAsJobTitleAndSalary.size(); ++defaultSizedIntegerVariableIndexingIntoEmployeesVectorWhichIsAVectorOfEmployeeRecordsEachOfWhichContainsPersonalInformationSuchAsFirstNameLastNameDateOfBirthAndRegisteredResidenceAsWellAsProfessionalInformationSuchAsJobTitleAndSalary_ThisVariableWasAddedByChiefSoftwareArchitectJohnDoeOnTheEveningOfWednesdayNovember12th2008RightBeforeDinner)

    What if I don't know what "++" does? Better to encapsulate that in a method called pleaseIncrementThisValueByOneBeforeIGoAnyFurther

  • facilisi (unregistered) in reply to LAN Mind
    LAN Mind:
    JohnB:
    The *real* WTF: people complaining about naming conventions in an application that truly works.

    God Lord, someone without a clue!

    FTFY. No offense but probably 50% of the articles here fit the same category of "works but does it in an idiotic way".

  • Georgem (unregistered) in reply to facilisi

    This isn't one of them. The principle is sound, the guy's just fallen foul of some odd coding idioms.

    So far, plenty of people have laughed and laughed at this naming convention, but I've seen little in the way of an actual argument about what's so wrong about it

  • venio (unregistered) in reply to mattmc
    mattmc:
    That camel has too many humps.
    Why would you care, you pervert?
  • Pony Princess (unregistered)

    Not a WTF. I wish there were more programs like this.

  • Anonymous (unregistered) in reply to Georgem
    Georgem:
    This isn't one of them. The principle is sound, the guy's just fallen foul of some odd coding idioms.

    So far, plenty of people have laughed and laughed at this naming convention, but I've seen little in the way of an actual argument about what's so wrong about it

    I can't believe you need this to be explained to you but what the hell, I'll help you out: the reason is line length. Virtually all (good) coding standards still recommend a maximum line length of 80 characters. This is due to the startlingly obvious fact that excessive line length decreases readability. What's the point in having "self-documenting code" when every single statement has to be split onto multiple lines due to the ridiculous method/variable names? Have you ever tried to read code in which every single method call traverses at least one line break? This should be well understood by anyone who actually codes to a standard, which I hope is most people round here.

  • EdS (unregistered)

    He's invented Cobol.

  • Jk (unregistered)

    I would have pissed myself laughing at him or I would have taken it as some elaborate joke.

  • Schobi (unregistered) in reply to SCB
    SCB:
    Steve the Cynic:
    Jester:
    I wonder if the lead developer was German? I think it is quite common among German developers to create names in a way that Germans create nouns ... just mix every word in a sentence and create a new noun.

    "Donaudampfschiffahrtsgesellschaftskapitän", which in English becomes four words: "Danube steamship company captain.

    Or the one I was told about when I was in school:

    Strassenbahnhaltestelle == Tram Stop. (Street railway stopping place, allegedly). The German version is not as impressively long as the captain's, but the contrast in length is awesome.

    Wikipedia gives us: Donaudampfschiffahrtselektrizitätenhauptbetriebswerkbauunterbeamtengesellschaft which, remakably, takes up less space that its English translation: "Association for subordinate officials of the head office management of the Danube steamboat electrical services".

    TRWTF are the readers of a website which mocks syntactically correct but still ill-used features who then go and wonder about hypothetical implications of language features that are syntactically correct but still ill-used.

  • Georgem (unregistered) in reply to Anonymous
    Anonymous:
    Georgem:
    This isn't one of them. The principle is sound, the guy's just fallen foul of some odd coding idioms.

    So far, plenty of people have laughed and laughed at this naming convention, but I've seen little in the way of an actual argument about what's so wrong about it

    I can't believe you need this to be explained to you but what the hell, I'll help you out: the reason is line length. Virtually all (good) coding standards still recommend a maximum line length of 80 characters. This is due to the startlingly obvious fact that excessive line length decreases readability. What's the point in having "self-documenting code" when every single statement has to be split onto multiple lines due to the ridiculous method/variable names? Have you ever tried to read code in which every single method call traverses at least one line break? This should be well understood by anyone who actually codes to a standard, which I hope is most people round here.

    Nicely cherry-picked. I have in fact said that the idiom helps one identify overly-busy pieces of code, so if you use it properly, line length does not become an issue. Also, 80 characters? In this day and age? Puh-lease!

  • no code, no cry (unregistered)

    case : wehaveonly2cases case : wehaveonly2casesandthisisthesecond case : wehaveonly2casesthisoneisforsolvingabugandshouldnotbecountedasarealcase case : crapanotherbugbutnomorethan4ok? case : ...

  • Georgem (unregistered) in reply to no code, no cry
    no code:
    case : wehaveonly2cases case : wehaveonly2casesandthisisthesecond case : wehaveonly2casesthisoneisforsolvingabugandshouldnotbecountedasarealcase case : crapanotherbugbutnomorethan4ok? case : ...

    A lesson in the maintenance overhead of conditional logic, rather than a critique of sensible naming conventions. Nice one

  • My Name? (unregistered) in reply to not german

    Geschwindigkeitsbegrenzung?

    Was ist Geschwindigkeitsbegrenzung?

    Did you mean 'rev limiter'?

  • Ouch! (unregistered) in reply to My Name?
    My Name?:
    Geschwindigkeitsbegrenzung?

    Was ist Geschwindigkeitsbegrenzung?

    Did you mean 'rev limiter'?

    No, it is "speed limit", as not german said. It's even correctly spelled. speed = Geschwindigkeit (note that velocity translates to the same word, deutsche Sparache, arme Sprache) limit = Grenze, Begrenzung

    A 'rev limiter' would be a Drehzahlbegrenzer.

  • unekdoud (unregistered)

    /* This is what an actual comment

    • looks like not those one word with
    • multiple capital letter comments
    • you've all been doing it wrong. */
  • Georgem (unregistered) in reply to unekdoud
    unekdoud:
    /* This is what an actual comment * looks like not those one word with * multiple capital letter comments * you've all been doing it wrong. */

    soYouHaveNoIdeaWhatThisMeans?

  • My Name? (unregistered) in reply to Ouch!
    Ouch!:
    My Name?:
    Geschwindigkeitsbegrenzung?

    Was ist Geschwindigkeitsbegrenzung?

    Did you mean 'rev limiter'?

    No, it is "speed limit", as not german said. It's even correctly spelled.

    I know the diff between speed limit and rev limit. My comment had been meant as a joke on the fact that there is no general speed limit on German motorways (Autobahn).

  • My Name? (unregistered) in reply to Georgem
    Georgem:
    unekdoud:
    /* This is what an actual comment * looks like not those one word with * multiple capital letter comments * you've all been doing it wrong. */

    soYouHaveNoIdeaWhatThisMeans?

    LineSeven: ErrorInCamelCaseExpression: FirstCharNotCapitalized!

  • My Name? (unregistered) in reply to Ouch!
    Ouch!:
    speed = Geschwindigkeit (note that velocity translates to the same word,...
    I always thought that a 'velocity' is a city where they ride only on bicycles and would translate to 'Fahrradstadt'.

    SCNR

  • P. Edant (unregistered) in reply to My Name?
    My Name?:
    Georgem:
    unekdoud:
    /* This is what an actual comment * looks like not those one word with * multiple capital letter comments * you've all been doing it wrong. */

    soYouHaveNoIdeaWhatThisMeans?

    LineSeven: ErrorInCamelCaseExpression: FirstCharNotCapitalized!

    That's because it was a method name, not a type

  • Kirby L. Wallace (unregistered)

    Imagine the fun he would have had, back in the day, when the compiler would have ignored anything past, say, 16 chars in a function name.

    DoInInventoryAndThenInBackOrders() and DoInInventoryAndThenDELETEBackOrders()

    ...would have both done the exact same thing!

    Captcha: enim

    enim...ahhh... Uhmmm. What I need after reading code like this.

  • Ouch! (unregistered) in reply to My Name?
    My Name?:
    Ouch!:
    speed = Geschwindigkeit (note that velocity translates to the same word,...
    I always thought that a 'velocity' is a city where they ride only on bicycles and would translate to 'Fahrradstadt'.

    SCNR

    Only in Schwyzerdütsch.
  • Mark (unregistered) in reply to xtremezone
    xtremezone:
    In college, the Visual Basic textbook we used and our instructor said that we should use verbosely descriptive names for everything and that the limitations on identifier length are a thing of the past. At the time, it sort of made sense. Still, the textbook actually used intIndex instead of i! Which I was OK with, at the time, but now it's just insane.
    // This...
    For i = 0 To 10
        a(i) = b(i) + c(i)
    Next
    // Versus this...
    For intIndex = 0 To 10
        arrAlpha(intIndex) = arrBeta(intIndex) + arrCharlie(intIndex)
    Next
    After a little more experience and trying the verbose way, I eventually learned that shorter names often result in clearer code. If necessary, a comment can be left to explain what an identifier means, but when it's actually used through the code, it can make a particular operation much clearer when you use short names.
    // This...
    a = b / c * d + e;
    // Versus this...
    TotalAmount = SomeValue / SomeOtherValue * ThisEmployeeValue + _
            ThatDepartmentValue;
    It's a lot easier to scan 18 characters than it is to scan 83.

    Absolutely. The more local in scope, the shorter. Temps are a single char or a1, a2, b1, b2.

    Larger locals try not to exceed 4 chars. The heavier a (class instance) is the longer its name, but if it is used a lot give it a Short special name: o_cust or oCu and not "CustomerObject".

    static functions should be NounVerb[Predicate/Adverb/Adjective](Noun n_, Data d_): HoundReleaseHell(Hound h_, int fanglen_)

    singletons : God.Is or God.Iam, not God.Instance

    Member Interface 'functions' are of three types:

    Commands- return SUCCESS and cause state changes, overridden Events- return void and should be overloaded to retain simplicity from callers view: o.evt(EvtBtn e_), o.evt(EvtData e_) Queries- return information and do not cause state change.

    Keep code as compact as possible, but do not do multiline statements. You should be able to glance at a clump of code and sense its form. The larger the clump you can maintain this on-sight legibility with the better.

    If your function takes up more than you can view, realize that you're 'copy-coding' (spelling things out simply because its easier at the moment) and not 'smart-coding' (no redundancy)

    Mantra: "The code is a map of itself"

  • pfwd (unregistered)

    yuk

  • ander (unregistered)

    TASM had a 32 character limit on label names.

  • oksupra.com (unregistered)

    Supra shoes are so popular all over the world. Whatever you take on Supra being in the Supra Skytop Shoes market. Now Supra Strapped Shoes also very popular attention. It is nice that they actually took the time to make Supra Skate Shoes that work well. Supra shoes is a brand that has been inspired, designed and marketed by passionate individuals. We have brought to you the fullest selection of Supra footwear at cheapest price.

  • Michael Hardeman (unregistered) in reply to rant64

    we do, it's called _

    use it, it doesn't bite

  • Dan (unregistered)

    If I ever had to maintain code written like this the first thing I would do is run it through an obfuscator so all the variables became "int1, char6, array4". I genuinely believe that would be easier to read..

  • Kevin Marco Erler (unregistered) in reply to rant64

    Regarding the comment: „We Need To Have Support For Spaces In Variables And Function Names = True;“ –

    Fun fact: In the meanwhile there are a programming language extension (Spock) based on Groovy where you can write Callables with spaces and other special char’s in their names: Java / JVM -> Groovy -> Spock

    E.g.: def "This test case check that the checkout to proceed button is available and visible. So you the button can clicked."(){ }

    These Callables are also usable with iterators (e.g. for a list / array of Test Cases with several inputs (e.g. several browser drivers, different URLs / Shop mandants/channels, etc.)).

    Thats really freaky, but for Test Case development, parallel Test Case Execution and the output / log of Test Cases it‘s really good.

    :D

Leave a comment on “CodeThatDocumentsItselfSoWellItDoesNotNeedComments”

Log In or post as a guest

Replying to comment #:

« Return to Article