Pwd stands for: ________? Correct, you guessed it! Once an abbreviation or acronym becomes widely used it makes sense to use it as a variable name for as long as you live.
Why I'll never abbreviate a variable as long as I live
21–30 of 111 posts
Re: Why I'll never abbreviate a variable as long as I live
#22Some people also hate typing out slightly longer variable names and what not. I try to emphasize that a section of code will tend to be read more times that it is written, and therefore readability is more important. It's a frustrating battle sometimes, though.
[0] Exacerbating the problem of using the wrong variable is the fact that much existing code uses implicit types...
Re: Why I'll never abbreviate a variable as long as I live
#23If the variables had been named timeOfTenPercentHeightOnTheFallingEdge and timeOfTenPercentHeightOnTheRisingEdge it probably would have still been hard to notice that they had been swapped in that one line.
Re: Why I'll never abbreviate a variable as long as I live
#24Re: Why I'll never abbreviate a variable as long as I live
#25I definitely prefer more verbose names to abbreviated ones, but I'm not sure that never abbreviating a variable name is the right way to go either. Surely there's a middle ground between `Ttpfe` and `timeOfTenPercentHeightOnTheFallingEdge`?
I like using static types to avoid these sorts of problems. Modern languages like Swift, Rust and Haskell let you make zero-overhead type wrappers around other types.
So here they could have defined `newtype RisingEdge(Float)` and `newtype FallingEdge(Float)`, and then use those types in the function parameters as appropriate.
Helps shorten function names to boot!
Re: Why I'll never abbreviate a variable as long as I live
#26If the variables had been named timeOfTenPercentHeightOnTheFallingEdge and timeOfTenPercentHeightOnTheRisingEdge it probably would have still been hard to notice that they had been swapped in that one line.
That said, you raise a fair point - we don't know how this bug got there. If it was a simple typo like above then the verbose names would have prevented it. If it was a logic error by the programmer (For whatever reason), then you're right that the name wouldn't matter because they typed the one they intended, it just wasn't the right one to use.
Re: Why I'll never abbreviate a variable as long as I live
#27Anyone else feel a bit uncomfortable reading the level of detail in this post?
Hope those systems are now declassified for his career's sake.
Re: Why I'll never abbreviate a variable as long as I live
#28Pwd stands for: ________? Correct, you guessed it! Once an abbreviation or acronym becomes widely used it makes sense to use it as a variable name for as long as you live.
A probably worse trap is "temp". Is it temporary or temperature?
Re: Why I'll never abbreviate a variable as long as I live
#29Anyone else feel a bit uncomfortable reading the level of detail in this post?
Re: Why I'll never abbreviate a variable as long as I live
#30I think this is the right choice, but my code reviewer didn't. But he didn't click on the quora link.
Why is okay for mathemeticians to abbreviate things but programmers? Is it because they deal in more abstract entities where the name is irrelevant?