• htg (unregistered) in reply to Vector
    Vector:
    When you see the four letters T, L, W, and H, all declared in the same statement, intuitively almost anybody can (should) link them to top, left, width, and height. Assuming the method deals with positions of some sort, those variables should lend their names even further to their purpose.

    My point is, there's got to be a balance between "Yes, this is a good coding practice" and "It's blinding fucking obvious what's going on here."

    Maybe in a fit of worthless programmer time someone wrote a tool to verify coding standards, and stuck it in every compile. It probably took $1000 to develop this pointless annoying nitpicking deviation from common sense as well, yet that programmer uses it as example code at job interviews.

    So regardless of the obviousness, a bunch of warnings would pop up each time:

    warning : variable 'T' violates coding standards variable name cannot differ by one character warning : variable 'T' violates coding standards no comment for variable warning : variable 'L' violates coding standards variable name cannot differ by one character warning : variable 'L' violates coding standards no comment for variable warning : variable 'W' violates coding standards variable name cannot differ by one character warning : variable 'W' violates coding standards no comment for variable warning : variable 'H' violates coding standards variable name cannot differ by one character warning : variable 'H' violates coding standards no comment for variable

  • (cs) in reply to mh
    mh:
    I see nothing wrong with the original. Presumably at some stage the coder is going to use x and y for positioning.

    This is standard mathematics that every 12 year old learns.

    Somebody who doesn't intuitively understand what's going on there has no business writing code in the first place.

    Using TT/LL/etc actually only serves to obfuscate what were originally very clear variable names.

    Using the full names would only expose the rigid application of this standard in this case for the farce it is:

    int Top, Left, Bottom, Right; // Top, Left, Bottom, Right
    

    Someone else has already pointed out that you can do away with some commenting if you spell the name out.

    int Top, Left, Bottom, Right;
  • htg (unregistered) in reply to Loren Pechtel
    Loren Pechtel:
    I definitely agree. My philosophy on coding is virtually zero comments. If a comment is needed that normally means the code isn't clear enough. This does occasionally mean extra procedure calls for no reason other than naming what I'm doing but the runtime cost of that is trivial.

    So you think you only need to comment the "how" aspect?

    What happened to the "why?" aspect? Why are you doing that? Why that particular way? Why that order? Why is that tweak to that integer there? Oh, it's for compatibility with xyz!

    Quite often in complex code it just makes sense to describe the "what" as well, because the system is so complex that the new hire would not be able to see at a glance what was going on. By complex I don't mean "iter += 1;", that is the code that can remain uncommented (if earlier there's a good why and what for the overall block of code).

    And the "where"? Yes, comment those database query methods, comment what each index is for populating that prepared statement or querying the result set is. Some day someone will alter the prepared statement and things will go wrong elsewhere, and the comments will let you see quickly where it went wrong.

  • me (unregistered)

    I would have just added the commment

  • (cs) in reply to brazzy
    brazzy:
    IMO assigning otherwise unused variables instead of chaining function calls generally is BAD for code readability and maintainability. The reason being that every variable adds state and thereby complexity. The fewer variables you need to implement the desired behaviour, the better. Heck, purely functional programming languages don't even HAVE variables!

    I disagree. In fact, even in functional languages, I find myself doing this.

    Instead of:

    (foo a b (bar a (baz c d (goo e f) e) (baz 2) c) (goo x y z))

    (formatted any way you like)

    I would rather see this any day of the week:

    (let* ((t1 (goo e f))
           (t2 (baz c d t1 e))
           (t3 (bar a t2 (baz 2) c))
           (t4 (goo x y z))
           (t5 (foo a b t3 t4))
           )
       t5)

    Now imagine that with readable, meaningful names for t1-t5.

    (Sometimes you could break up such deep nestings with auxiliary functions, but now you have a huge proliferation of those.)

  • Zygo (unregistered) in reply to Dana
    Dana:
    I disagree that comments are NEVER needed.

    If your code is well written and descriptive, comments may not be needed to tell you WHAT the code is doing, but they are extremely helpful when you need to know WHY the code is doing what it is doing.

    That isn't always immediately obvious in the case of bug fixes, workarounds, and things that are done because of stupid policy decisions that overrode sane technical practice.

    Indeed, those are three of the only five reasons why I ever write comments.

    My #1 commenting reason is the stupid policy decisions and insane technical practices. No amount of variable naming can express that a solvable problem remains in a shipping product because of an uninformed decision-making process. Not that I haven't tried--I've thrown exceptions of type FixmeHaveToStopLoadingFileNOWSeeBug953WeWillNotFixInThisRelease, for instance.

    My second commenting reason is workarounds in my dependencies (e.g. // this library function crashes when passed 42, so handle that case differently).

    My third reason is for code that is not written in the most straightforward possible form because the most straightforward possible form is too costly. This covers hand-optimized code, because after several passes through a compile-test-profile-edit cycle, even the clearest algorithms become impenetrable.

    My fourth commenting reason is bug fixes, although I lump many of these in with reason #1. Generally if a bug is truly fixed there is no need to write a comment to that effect (the BTS and SCM systems both have this historical data, and fixed bugs are irrelevant to future code maintainers). If the the bug fix is incomplete due to a policy decision, then it's technically an unfixed bug. It is worthwhile to bring unfixed bugs to the attention of future code maintainers; however, not all policy decisions are stupid, so unfixed bugs due to non-stupid policy decisions get their own category.

    My fifth reason for commenting is the boilerplate copyright statements at the beginning of each file. ;-)

    For the purposes of this comment ;-) I'm counting other code documentation (theory of operation, maintenance hints, etc) separately from comments that appear interleaved with the code itself.

  • (cs) in reply to Random832
    Random832:
    While the more-than-one-letter rule sounds reasonable when you explain it in terms of "day" vs "days", and these particular variables should be descriptively named, the rule actually forbids single-character names altogether, even when they would be reasonable to use.

    Lies, all lies. It doesn't forbid single-character variables, it forbids MORE THAN ONE single-character variable. The first one is fine. (Although the first one promptly forbids all two-letter variable names containing the utilized letter...)

  • GreyWolf (unregistered) in reply to Mr Ascii
    In Fortran IV & 77, variables starting with I-N were implicitly defined as INTEGERs, all others were REAL. So, naturally, when you needed to iterate loops, you used I, J, K, L, M, and N. Of course variable names were limited to 6 characters so having decently descriptive variable names was difficult.
    And before that in FORTRAN II my learned friend. The rest of you, bow down before the mightiest of languages, spoken by the giants of the early days, beside whom ye are mere coders.
  • Greyhound (unregistered) in reply to mh

    But try searching a large body of text for t, l, x and y tt, ll, xx, yy is much easier to work with.

  • Archituethis Dux (unregistered) in reply to stevekj
    stevekj:
    Strider:
    viola, problem solved, new coder learns.

    How did violas get into this?

    For some reason they seem to show up a lot more often than you'd expect for an otherwise underappreciated harmonic string instrument, and in the oddest places.

    -- A viola player

    Reminds me of a Victor Borge comment:

    What's the difference between a violin and a viola?
    A viola burns longer.

  • Nekrotzar (unregistered) in reply to htg

    [quote user="htg"][quote user="Vector"] Maybe in a fit of worthless programmer time someone wrote a tool to verify coding standards, and stuck it in every compile. It probably took $1000 to develop this pointless annoying nitpicking deviation from common sense as well, yet that programmer uses it as example code at job interviews.

    So regardless of the obviousness, a bunch of warnings would pop up each time:

    warning : variable 'T' violates coding standards variable name cannot differ by one character [/quote] Some 20 years ago I had a summer job at a company that did Ada consulting. Basically, companies that got big DoD contracts would fire my employer to tell them how to write Ada code.

    Part of the services was a Style Guide, and, yes, there was a StyleChecker tool (that I worked on) that enforced the guidelines and produced lengthy reports on violations in the code. (The company that hired us would presumably use these reports to determine which programmers got perks like parking spots, chairs, and lunch breaks.)

    One of the rules was that every control structure had to have a comment. That doesn't strike me as ridiculous (overkill but not a total WTF), and it should be easy to come up with an example that shows the value of following this practice. Yet the example included in the Style Guide totally missed the boat:

    -- if CurrentAltitude greater than MaxAltitude
    if CurrentAltitude > MaxAltitude then
    begin
     ...
    end
    

    Then there were some style guidelines that struck me as bizarre. In variable declarations, the colons all had to line up:

    Height                                       : Integer;
    Width                                        : Integer;
    NumberOfSecondsUntilNextMajorSimilationEvent : Integer;
    

    Some consideration was given to requiring that the longest variable be listed first, but this never did get adopted.

    My captcha is nobody else's business.

  • (cs)

    Which do you like better? Personally I use the second one.

    int numberOfDaysSinceGeorgeRanTheReportLastTime; int days; //How many days has it been since running the report

  • (cs) in reply to Blablah
    Blablah:

    What about when you see a single T, a hundred lines of code later?

    I smack someone for writing a function several hundred lines long.

  • Stefan W. (unregistered)

    bind, mind, find, may, day ram, rem, rom, roi

    who can confuse that? Figtht silly standards!

    I would have named those variables ta, lb, wc, hd; // abcd - next charcter: e

  • (cs) in reply to Greyhound

    Greyhound: That's easy. Just enable the "whole word only" option in your search dialog box.

  • (cs) in reply to Strider
    Strider:
    jaspax:
    When I see something like this I wonder: is the coder stupid? Did they truly not understand the point of the coding standard? Or are they deliberately trying to undermine it?

    I disagree, he did understand the point of the coding standards. They had coding standards, he revised his code to those standards, what's wrong with that?

    I say it's their fault for not adding an additional rule: 3. Variable names should be descriptive.

    In which case he'd have had to name his variables.

    int Top, Left, Width, Height;

    viola, problem solved, new coder learns.

    Not always. One of the guys here is Russian, and likes to name variables with transliterated Russian. Nobody else can understand this guy's code, but it's compliant.
  • GreyWolf (unregistered) in reply to mh
    mh:
    int Top, Left, Bottom, Right; // Top, Left, Bottom, Right

    Are we missing the point? These names do not say Top etc OF WHAT?

    You'll have more than one 'thing' that has a Top: the window, the bitmap, the dynamically-inserted content, the Panic button etc etc etc.

    May I also suggest that for each of those, you would document what the measurement is relative to (Window_Top is relative to and contained within Desktop) and maybe what the unit is: pixels, centimeters, NASA_Confusion_Units).

  • (cs) in reply to anon
    anon:
    Strider:
    As a side note, I don't know how many times i've switched up my i's and j's in nested loops and totally befuddled myself for hours...or minutes...they look so similar, who thought to use those two anyway?

    I'm surprised no one has mentioned it yet, but it goes way back to FORTRAN on punchcards where i-n were automatically typed integers and therefore handy for for loops.

    And why do you think Fortran chose those?

    Using i-n to store natural numbers predates programming by at least 60 years. Probably more like 120 years, though I don't have access to any original, c. 1800 books to verify. They're used as indices for countable sequences in mathematics.

  • Standard Bearer (unregistered)

    I like the fact that the coder couldn't be bothered to name the variables Top, Left, Width, Height, but then put that text in the comments.

    The comments could have been left out if they had.

  • Terrier (unregistered)

    The whole key to this is scope. If these weren't public variables and the routine using them was 6 lines long - what the hell is the point? Variables should almost always be actual words but if the effect is localized to a small space it is extreme nitpicking to pick standards over common sense.

  • (cs) in reply to Greyhound
    Greyhound:
    But try searching a large body of text for t, l, x and y tt, ll, xx, yy is much easier to work with.
    /[^[:alpha:]][tlhw][^[:alpha:]] There are times when regular expressions are quick and useful. More often in the IDE than in the code. :-)
  • (cs)

    Width of WHAT? Height of WHAT?

    The names Top, Bottom, Width, Height are not very descriptive. Probably some window or other, but who knows? And which window? Any window?

  • (cs)

    Oops. GreyWolf beat me to it.

  • (cs) in reply to Foosball Girl In My Dreams

    One of my personal pet peeves are unfilled comments like those below - takes up 80% of a file and adds nothing:

    package x.y.z;
    /**
     * File:         ClassName.java
     * Author:  
     * Written: 
     * Purpose:
     * Usage:
     * Dependencies:
     * Notes:
     * History:
     */
    
    /**
     * Function:     theFunction
     * Author:  
     * Written:
     * Purpose: 
     * Parameters: 
     * Return:
     * Exception:
     * History:
     */
    public int theFunction() {
      ...
    }
    
    /**
     * Function:     theOtherFunction
     * Author:  
     * Written: 
     * Purpose: 
     * Parameters: 
     * Return:
     * Exception:
     * History:
     */
    public int theOtherFunction() {
      ...
    }
    
    
  • (cs) in reply to Nekrotzar
    Nekrotzar:

    One of the rules was that every control structure had to have a comment. That doesn't strike me as ridiculous (overkill but not a total WTF), and it should be easy to come up with an example that shows the value of following this practice. Yet the example included in the Style Guide totally missed the boat:

    -- if CurrentAltitude greater than MaxAltitude
    if CurrentAltitude > MaxAltitude then
    begin
     ...
    end
    

    The comment should have said:

    -- If the current altitude is greater than the max altitude, then we need to <blah, blah blah>
    
  • KNY (unregistered) in reply to Anon
    Anon:

    I agree about using a better font - on windows, the Consolas and Anonymous fonts looks pretty good.

    I always code in Comic Sans, personally.

  • (cs) in reply to vertagano
    vertagano:
    /[^[:alpha:]][tlhw][^[:alpha:]] There are times when regular expressions are quick and useful. More often in the IDE than in the code. :-)
    Your regular expression will not find cases where the variable appears at the start or end of a line. It will also produce spurious matches for other valid identifiers like "w_t_f".

    Try /\b[tlhw]\b/ or /<[tlhw]>/, depending on the flavour you're using. If your environment doesn't support any form of zero-width word-edge match, delete it and install something better.

    (Of course, the real WTF is that you're using POSIX character classes...)

  • nobody (unregistered)

    I once had a Russian write some code that used c for "sequence number"

    c in the Cyrillic alphabet has the "s" sound.

    That person also didn't indent code and used single character variable names, and got upset when told to change.

    Fortunately for me, someone else indented the code. Visual Studio refused to do so for me.

  • Andrew (unregistered) in reply to Strider
    Strider:
    FeepingCreature:
    stevekj:
    Strider:
    viola, problem solved, new coder learns.

    How did violas get into this?

    For some reason they seem to show up a lot more often than you'd expect for an otherwise underappreciated harmonic string instrument, and in the oddest places.

    -- A viola player

    I'm not sure, I think it's the setup for a joke. I first found it in the Wizardry series of comedic fantasy books (made of awesome), but I'm sure its roots lie elsewhere.

    <person1> BlaBlaBLABLAblablaaaablaBLA, and viola! <person2> It's voila. <person1> Not the way I play it!

    Doh! Those two words should have at least a two letter difference!

    If only english followed such strict c0ding standards...

    As a side note, I don't know how many times i've switched up my i's and j's in nested loops and totally befuddled myself for hours...or minutes...they look so similar, who thought to use those two anyway?

    Somebody in the 17th or 18th century mutated I into J. Latin has no J. "Jehova" in Christian texts starts with I.

    Mathematician's notes have early J references. 3D unit vectors are (i, j, k). Complex numbers can be written with sqrt(-1) as +i or +j.

  • (cs) in reply to poopdeville
    poopdeville:
    anon:
    Strider:
    As a side note, I don't know how many times i've switched up my i's and j's in nested loops and totally befuddled myself for hours...or minutes...they look so similar, who thought to use those two anyway?

    I'm surprised no one has mentioned it yet, but it goes way back to FORTRAN on punchcards where i-n were automatically typed integers and therefore handy for for loops.

    And why do you think Fortran chose those?

    Using i-n to store natural numbers predates programming by at least 60 years. Probably more like 120 years, though I don't have access to any original, c. 1800 books to verify. They're used as indices for countable sequences in mathematics.

    Exactly! Every time someone complains about the use of i, j, k, etc., as index variables, I have to wonder if he's ever looked at the pages of an algebra book, specifically summations and matrix positions. i and j are as common for denoting indices as f is for a general function.

  • (cs) in reply to iToad
    iToad:
    Back in the day, programmers used single-letter variable names and no whitespace, because Fortran IV statements had to fit into columns 7-72 of a punched card. Programming languages have advanced considerably since 1965, and it is much easier to use reasonably descriptive variable names in software.

    By the way, use of one or two-letter variables beginning with i through n as loop indexes also comes from Fortran. In old-school Fortran, variables beginning with i to n were (by default) integer variables, and variables beginning with the other letters were floating-point variables.

    I knew that the "i" for integers was from an old programming language. Note that Fortan didn't have named data types until Fortran 66: http://en.wikipedia.org/wiki/Fortran

    FORTRAN 66 included:... INTEGER, REAL, DOUBLE PRECISION, COMPLEX, and LOGICAL data types
  • (cs) in reply to Iago
    Iago:
    vertagano:
    /[^[:alpha:]][tlhw][^[:alpha:]] There are times when regular expressions are quick and useful. More often in the IDE than in the code. :-)
    Your regular expression will not find cases where the variable appears at the start or end of a line. It will also produce spurious matches for other valid identifiers like "w_t_f".

    Try /\b[tlhw]\b/ or /<[tlhw]>/, depending on the flavour you're using. If your environment doesn't support any form of zero-width word-edge match, delete it and install something better.

    (Of course, the real WTF is that you're using POSIX character classes...)

    Our coding style 1.) Require two spaces in front of any line of code and 2.) does not permit underscores outside of text literals. Therefore, the expression I gave works in my environment. There might still be some extraneous matches, but since I'm using it to search (not to replace), I can just press "n" and move to the next when I see one. Sorry about the POSIX, but the program we use is very esoteric, so to try for something more standard, I opened vi -- and it didn't accept "\b", so [^:alpha:] was the next thing that came to mind. < > would match "<" and ">" in our program; <> is used for capturing groups.

  • Fregas (unregistered)

    We have a very consistent naming convention at our company. We like to prefix all method level variables with "m" and all instance variables with "i". Then we use a form of hungarian notation where the name of the variable specifies the type such as "str" or "int". Then we just increment the variables with a number 1,2,3 and put comments next to the declaration.

    This gives us very consistent variable names such as:

    iStr1 //firstname iStr2 //lastname iStrBuilder1 //string builder to send email iBool1 //Is this user active? iBool2 //Does this customer have sex on a regular basis? iInt1 //what is the average wing velocity of a laden sparrow? iMyEnum1 // african or european? iInt2 //how many fingers am i holding up? mInt1 //local iterator for this for loop mLong //number of times this method has thrown an out of memory exception

    ... and so on...

  • ForcedSterilizationsForAll (unregistered) in reply to Strider
    Strider:
    FeepingCreature:
    stevekj:
    Strider:
    viola, problem solved, new coder learns.

    How did violas get into this?

    For some reason they seem to show up a lot more often than you'd expect for an otherwise underappreciated harmonic string instrument, and in the oddest places.

    -- A viola player

    I'm not sure, I think it's the setup for a joke. I first found it in the Wizardry series of comedic fantasy books (made of awesome), but I'm sure its roots lie elsewhere.

    <person1> BlaBlaBLABLAblablaaaablaBLA, and viola! <person2> It's voila. <person1> Not the way I play it!

    Doh! Those two words should have at least a two letter difference!

    If only english followed such strict c0ding standards...

    As a side note, I don't know how many times i've switched up my i's and j's in nested loops and totally befuddled myself for hours...or minutes...they look so similar, who thought to use those two anyway?

    I preferred using X and Y for my loops

  • (cs) in reply to Fregas
    Fregas:
    We have a very consistent naming convention at our company. We like to prefix all method level variables with "m" and all instance variables with "i". Then we use a form of hungarian notation where the name of the variable specifies the type such as "str" or "int". Then we just increment the variables with a number 1,2,3 and put comments next to the declaration.

    This gives us very consistent variable names such as:

    iStr1 //firstname iStr2 //lastname iStrBuilder1 //string builder to send email iBool1 //Is this user active? iBool2 //Does this customer have sex on a regular basis? iInt1 //what is the average wing velocity of a laden sparrow? iMyEnum1 // african or european? iInt2 //how many fingers am i holding up? mInt1 //local iterator for this for loop mLong //number of times this method has thrown an out of memory exception

    ... and so on...

    No way. Do you keep the variable comments everytime you use any variables?

  • MZ (unregistered)

    The real WTF is the stupid rule here. I am pretty sure the new guy was doing it out of protest.

  • (cs) in reply to Dana
    Dana:
    I disagree that comments are NEVER needed.

    If your code is well written and descriptive, comments may not be needed to tell you WHAT the code is doing, but they are extremely helpful when you need to know WHY the code is doing what it is doing.

    I don't consider that "commenting the code", rather "commenting the algorithm". You should have comments in your code, but you shouldn't need to comment the code itself. I find that if I ever write a comment about what the code is doing, I refactor and the need for the comment goes away.

  • (cs) in reply to Fregas
    Fregas:
    We have a very consistent naming convention at our company. We like to prefix all method level variables with "m" and all instance variables with "i". Then we use a form of hungarian notation where the name of the variable specifies the type such as "str" or "int". Then we just increment the variables with a number 1,2,3 and put comments next to the declaration.

    This gives us very consistent variable names such as:

    iStr1 //firstname iStr2 //lastname iStrBuilder1 //string builder to send email iBool1 //Is this user active? iBool2 //Does this customer have sex on a regular basis? iInt1 //what is the average wing velocity of a laden sparrow? iMyEnum1 // african or european? iInt2 //how many fingers am i holding up? mInt1 //local iterator for this for loop mLong //number of times this method has thrown an out of memory exception

    ... and so on...

    My irony recognition unit is currently in the shop for it's 10 year overhaul. Please tell me this is a joke!
  • James Schend (unregistered) in reply to Strider
    Strider:
    FeepingCreature:
    stevekj:
    Strider:
    viola, problem solved, new coder learns.

    How did violas get into this?

    For some reason they seem to show up a lot more often than you'd expect for an otherwise underappreciated harmonic string instrument, and in the oddest places.

    -- A viola player

    I'm not sure, I think it's the setup for a joke. I first found it in the Wizardry series of comedic fantasy books (made of awesome), but I'm sure its roots lie elsewhere.

    <person1> BlaBlaBLABLAblablaaaablaBLA, and viola! <person2> It's voila. <person1> Not the way I play it!

    Doh! Those two words should have at least a two letter difference!

    If only english followed such strict c0ding standards...

    As a side note, I don't know how many times i've switched up my i's and j's in nested loops and totally befuddled myself for hours...or minutes...they look so similar, who thought to use those two anyway?

    I dunno, I always learned to use x, y, z for loops. Although my current employer has convinced me to move to i,j,k if only to fit in with existing code. I guess x, y, z could be a problem for apps which use a 3-d coordinate system.

  • Zygo (unregistered) in reply to GreyWolf
    GreyWolf:
    mh:
    int Top, Left, Bottom, Right; // Top, Left, Bottom, Right

    Are we missing the point? These names do not say Top etc OF WHAT?

    You'll have more than one 'thing' that has a Top: the window, the bitmap, the dynamically-inserted content, the Panic button etc etc etc.

    Only for global, static, and member variables. Within a function, method, or block, there may easily be exactly one thing in local scope that has a top, left, bottom, or right.

    For member variables, it can depend on the context. For example, if the four variables are members of a class named "Rectangle", it is reasonable to assume that they refer to the extents of the Rectangle stored at this. Any other Rectangle would need a prefix, like window.Left or bitmap_ptr->Left. If you really want to be clear, you could use this->Left, but at the risk of losing optimization due to pointer aliasing rules.

    Ironically, just last month I had to audit two different software packages because they use Qt's QRect class, which has a very slightly different definition of "bottom" and "right" than the code that was using them expected. In QRect, width() == right() - left() + 1, which is different from the way many other rectangle implementations do it.

    GreyWolf:
    May I also suggest that for each of those, you would document what the measurement is relative to (Window_Top is relative to and contained within Desktop) and maybe what the unit is: pixels, centimeters, NASA_Confusion_Units).

    At one point we had banned the words "left", "right", "top", "bottom", "up", and "down". As far as I know they're still banned (unless you're talking about members of the QRect class).

    The systems we deal with involve cameras, objects being photographed, and robots to move the objects and cameras around so different areas on the object's surface can be photographed. Our software moves things around taking pictures, then assembles the images back together. Cameras can be oriented in any of 4 90-degree rotations, and in some cases optional mirrors or lenses can be installed in the optical paths which flip one or both image axes. The robots all have their own axis orientations and units.

    Part of the calibration of this system involves figuring out how "move motor #2 forward by 300 steps" translates into a change in the area on the object observed through the image coming from the camera. You can get exactly the same result if the object moves to the left, or the camera moves to the right. The polarity of the axis controller might be reversed (so right becomes left) or some compound lens might flip the image (so top becomes bottom), or both might happen at the same time (so top is still bottom, but left is left again) and the object ends up moving to the left again but it's upside-down.

    Phrases like "moving to the left" have one and only one crystal clear meaning in our group's specialized technical jargon. The phrase, roughly translated, means "please give me a wedgie immediately, and make sure you pull hard enough to tie a bow with my underpants around the back of my ears this time."

  • Bozo the Engineer (unregistered) in reply to Vector

    T, L, W, H in the right context are obvious to a native English speaker. Top, Left, Width, Height can be resolved by anyone with an English to [Elbonian] dictionary.

    I am a native English speaker, so it's not a problem for me. But, I still get bitten all the time with one and two-letter abbreviations for jargon. Worse, I work in a place where there are multiple sources (software + subject domains + company internals) all contributing acronyms to the same code.

    Between touch typing and IDEs written in the past decade or more, what the heck are you saving? Would you like to buy a vowel?

    Captcha: kungfu. An appropriate reaction to programmers who thing 12 of their keystrokes are worth 5 minutes of my time.

  • Zygo (unregistered) in reply to Zygo
    Zygo:
    Only for global, static, and member variables. Within a function, method, or block, there may easily be exactly one thing in local scope that has a top, left, bottom, or right.

    One could say that if there is actually more than exactly one thing in local scope that could have a top, left, bottom, or right, you need to refactor until those things belong to distinct objects.

    This problem is endemic in crappy UI toolkits, where a whole pile of state of what should be different objects ends up in a single struct or class. Point-and-drool UI design tools make this worse, by exposing all of these as if they were properties of a single object.

    Why have windowLeft, desktopLeft, buttonLeft, iconLeft, etc, when you could simply have window, desktop, button, and icon, each with their own Left? window.Left is clear enough--we're talking about the left of a window. Have more than one window? Rename the window, but keep the Left.

  • (cs)

    IMHO, one-letter variable names are reserved for loop vars.

    Yes, all of them! In case I ever need to nestle 26 loops, why do you ask?

    ;-)

  • (cs) in reply to Strider
    Strider:
    FeepingCreature:
    stevekj:
    Strider:
    viola, problem solved, new coder learns.

    How did violas get into this?

    For some reason they seem to show up a lot more often than you'd expect for an otherwise underappreciated harmonic string instrument, and in the oddest places.

    -- A viola player

    I'm not sure, I think it's the setup for a joke. I first found it in the Wizardry series of comedic fantasy books (made of awesome), but I'm sure its roots lie elsewhere.

    <person1> BlaBlaBLABLAblablaaaablaBLA, and viola! <person2> It's voila. <person1> Not the way I play it!

    Doh! Those two words should have at least a two letter difference!

    If only english followed such strict c0ding standards...

    As a side note, I don't know how many times i've switched up my i's and j's in nested loops and totally befuddled myself for hours...or minutes...they look so similar, who thought to use those two anyway?

    A bit of math history is due here. In the "olden" days, before computers were even a twinkle in Woz's eye, the letters i,j,k were used to represent integers, x,y,z were used to represent real numbers, and m,n were used for limits on sums. Think Algebra & Calculus.

    Then, when computers came to be, mathematicians were among the first to spread into the field. Since symbolic logic fits well in both fields, the symbols i & j became hits.

    Yes, I'm a mathematician who writes too much code & reads too many books.

  • (cs)

    How about this? The variables are descriptive, but the comment is now no longer redundant:

    int Top, Left, Width, Height; // Width, Height, Top, Left respectively.

    The best variable name I have ever seen has to be:

    wotobrep

    My friend in college used it in a substring replace function in qbasic.

    Also I found that MS Visual Studio .net 2003 is incapable of using the Bitstream Vera Sans Mono font, which is a crying shame.

  • Anon (unregistered) in reply to Andrew
    Andrew:
    Complex numbers can be written with sqrt(-1) as +i or +j.

    In math it's almost always "i" for complex numbers. Unfortunately when the damn EEs got involved they couldn't use "i" because it was already used for current (like that is so important). So they used the next best thing.

  • Duc (unregistered) in reply to Chris DB

    Should it be something like

    foreach (Day day in workingDays) {...

    instead? It's actually much more descriptive.

  • YoungTeam97 (unregistered) in reply to GreyWolf
    GreyWolf:
    The rest of you, bow down before the mightiest of languages, spoken by the giants of the early days, beside whom ye are mere coders.
    Man, wasn't Joey supposed to be pushing his wheel chair around today? Senior care in this day and age...
  • (cs) in reply to Greyhound
    Greyhound:
    But try searching a large body of text for t, l, x and y tt, ll, xx, yy is much easier to work with.
    bash$ vim +"set hlsearch" "+/\<[tlxy]\>" large_body.txt
    

    bash$ less "+/<[tlxy]>" large_body.txt

    bash$ grep "<[tlxy]>" large_body.txt

    (And yes, you can also use those search patterns within vim/less, not just at the command line...)

    Addendum (2007-08-02 23:08): edit: Of course, nearly everyone beat me to it, but what the heck. Teaches me not to reply without reading all the comments, even when I'm that close to the end...

  • I (unregistered)

    Comments are unnecessary. That's why I never post any.

Leave a comment on “Coded to the Letter”

Log In or post as a guest

Replying to comment #:

« Return to Article