Comment On Really Descriptive Names

You've probably encountered more than your fair share of inadequately descriptive variable and function names. Debugging a function with variables named a, a1, a2, a0, aO, al, a1l, al1, aIl, a1I, and al1I is something I wouldn't wish on my worst enemy. [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: Really Descriptive Names

2007-11-07 09:04 • by wtf (unregistered)
With intellisense its not that bad.

not really a big deal

Re: Really Descriptive Names

2007-11-07 09:06 • by Brady Kelly (unregistered)
160107 in reply to 160106
wtf:
With intellisense its not that bad.

not really a big deal

IWasAboutToSayThatButYouBeatMeToItByAVerySmallMargin.

Re: Really Descriptive Names

2007-11-07 09:08 • by Ron (unregistered)
160108 in reply to 160107
Brady Kelly:
wtf:
With intellisense its not that bad.

not really a big deal

IWasAboutToSayThatButYouBeatMeToItByAVerySmallMargin.

IWasAboutToDoThatBut..... errm, nevermind

Re: Really Descriptive Names

2007-11-07 09:09 • by pitchingchris
160109 in reply to 160107
Brady Kelly:
wtf:
With intellisense its not that bad.

not really a big deal

IWasAboutToSayThatButYouBeatMeToItByAVerySmallMargin.


The goggles! They do nothing !

Re: Really Descriptive Names

2007-11-07 09:17 • by Kharkov (unregistered)
It reminds me of the naming conventions issued by IBM in the OS/2 programming documentation.

The only issue I ever had with this kind of descriptions was that the MS Pascal compiler truncated names after 64 characters, and to have function names differing only after this limit...

Re: Really Descriptive Names

2007-11-07 09:18 • by [ICR] (unregistered)
160111 in reply to 160106
wtf:
With intellisense its not that bad.

not really a big deal


Not to type, but to read and understand is still quite difficult. Personally I tend to use names longer than I should, but I have a limit of about half that.

Re: Really Descriptive Names

2007-11-07 09:18 • by Jens (unregistered)
And the variable names he passed are cool too:

SecurityContext and securityContext differ only in the capitalisation of first letter..

Brilliant !!!

Re: Really Descriptive Names

2007-11-07 09:20 • by [ICR] (unregistered)
160113 in reply to 160112
Jens:
And the variable names he passed are cool too:

SecurityContext and securityContext differ only in the capitalisation of first letter..

Brilliant !!!



That's not too bad. With a consistent naming convention and colour syntax highlighting it's pretty easy to tell the class name apart from the variable name.

Re: Really Descriptive Names

2007-11-07 09:20 • by Jens (unregistered)
160114 in reply to 160112
Jens:
And the variable names he passed are cool too:

SecurityContext and securityContext differ only in the capitalisation of first letter..

Brilliant !!!



oh ok, I just realised that it was the classname and the variablename that differ in first letter.. still not a bright thing to do..

Re: Really Descriptive Names

2007-11-07 09:23 • by sweavo (unregistered)
What language is that, that allows hyphens in identifiers?

Captcha: I'm not telling, but I laughed when I read it.

Re: Really Descriptive Names

2007-11-07 09:23 • by Welbog
160116 in reply to 160114
Jens:
oh ok, I just realised that it was the classname and the variablename that differ in first letter.. still not a bright thing to do..
This is a pretty common convention, from my point of view. How do you name single instances of classes?

Re: Really Descriptive Names

2007-11-07 09:25 • by poochner
160117 in reply to 160114
Jens:
Jens:
And the variable names he passed are cool too:

SecurityContext and securityContext differ only in the capitalisation of first letter..

Brilliant !!!



oh ok, I just realised that it was the classname and the variablename that differ in first letter.. still not a bright thing to do..

It's very common, though, in the case where the argument would simply be "some generic instance of this class." Better than "temp" or (God help us) "arg0".

Re: Really Descriptive Names

2007-11-07 09:26 • by wiregoat (unregistered)
160118 in reply to 160116
Hey, it beats having comments in the code. Those are just ugly.

Re: Really Descriptive Names

2007-11-07 09:32 • by jimjim (unregistered)

its easy to get long names in classes when you have to use prefix and suffixes, in example:

some_package_name_some_sub_package_class_name_data_replicated

Re: Really Descriptive Names

2007-11-07 09:38 • by OneMHz
"Organization copay"

Wait, what?

Re: Really Descriptive Names

2007-11-07 09:46 • by gabba
Where's the wtf? At least they didn't use hungarian.

Re: Really Descriptive Names

2007-11-07 09:46 • by barfman (unregistered)
yeoooooowwww!

That's a lot of reading. Verbosely uglier than anything I've had the luxury of seeing, thanks for sharing.

Give someone an inch, they take a mile...

Re: Really Descriptive Names

2007-11-07 09:51 • by Jon (unregistered)
the only wtf is perhaps using long variable names that don't make any sense. If they are that long and make perfect sense then I wouldn't mind it. The other WTF is the poster probably hasn't heard of intelisense :)

Re: Really Descriptive Names

2007-11-07 09:55 • by snoofle
160126 in reply to 160108
Jake:
Debugging a function with variables named a, a1, a2, a0, aO, al, a1l, al1, aIl, a1I, and al1I is something I wouldn't wish on my worst enemy.

I would!

Re: Really Descriptive Names

2007-11-07 09:57 • by -j (unregistered)
160127 in reply to 160124
If it encourages code like that, intelisense is neither intelligent nor makes any sense. Probably heresay on a winforum like this :-(

Re: Really Descriptive Names

2007-11-07 09:57 • by Me (unregistered)
160128 in reply to 160116
Welbog:
Jens:
oh ok, I just realised that it was the classname and the variablename that differ in first letter.. still not a bright thing to do..
This is a pretty common convention, from my point of view. How do you name single instances of classes?


ClassName: Car

Singleton: aCar

Re: Really Descriptive Names

2007-11-07 10:01 • by David Betz (unregistered)
OK, actually that's a great name. You want them to be self describing. Per the Microsoft Coding requirements, that's flawless. It's very common in a well-factored system.

Re: Really Descriptive Names

2007-11-07 10:03 • by David Betz (unregistered)
Er actually, nevermind that can't be Microsoft code. The name casing is in that obsolete Java-style camelCasing. So, I guess the name sucks as you don't do those long names in Java.

Re: Really Descriptive Names

2007-11-07 10:05 • by John Doe (unregistered)
160131 in reply to 160124
No, I think the real WTF is that there are multiple classes with a ton of functions with ridiculously long names that all vary by one or two words.

And I just looking at the function name again it has some words repeated like "product" and "copay".

getSalesOrderProductSupplierCopayDrugStrengthFormCountryManufacturerPharmacyCopayProductPrice

Now imagine a function like the following. I bet intellisense really helps when your trying to differentiate the two.

getSalesOrderCopayProductProductSupplierCopayManufacturerDrugStrengthFormPharmacyPrice

Re: Really Descriptive Names

2007-11-07 10:06 • by seymore15074
160132 in reply to 160106
wtf:
With intellisense its not that bad.

not really a big deal


I use vi. I would fall short of being very happy about it.

Re: Really Descriptive Names

2007-11-07 10:06 • by fanguad (unregistered)
That looks a lot like our code base... fortunately most of our class names are about 50-75% that length, although for many it doesn't really matter, since they've already passed the point of being reasonable.

For extra fun, try combining long class and variable names with an 80-character line limit (we do). Any variable assignment takes at least 2 lines, and most function calls take 4-5 lines.

Ugh.

Re: Really Descriptive Names

2007-11-07 10:06 • by anonny (unregistered)
160134 in reply to 160129
David Betz:
OK, actually that's a great name. You want them to be self describing. Per the Microsoft Coding requirements, that's flawless. It's very common in a well-factored system.
So tell me, then: What does it mean?

Re: Really Descriptive Names

2007-11-07 10:07 • by daniel c w
I do not think it is a F.
Fail to see what's so bad about it.
I would actually write that kind of code.


p.s.: I do also not tink it is a W or a T

Re: Really Descriptive Names

2007-11-07 10:13 • by Welbog
160136 in reply to 160128
Me:
Welbog:
Jens:
oh ok, I just realised that it was the classname and the variablename that differ in first letter.. still not a bright thing to do..
This is a pretty common convention, from my point of view. How do you name single instances of classes?
ClassName: Car

Singleton: aCar
That's a reasonable convention, but the difference between the class name and the instance name is still only one letter. Unless your ability to read case-sensitive code has been ruined by reading forums whose members don't capitalize or by case-insensitive programming languages (a WTF by itself), I don't really understand what the problem is with Car car = new Car();

Re: Really Descriptive Names

2007-11-07 10:18 • by ftw (unregistered)
160137 in reply to 160106
wtf:
With intellisense its not that bad.

not really a big deal


The real WTF is that so many developers think like this.

captcha: LongAndVerboseDoesNotEqualClearAndReadableYouIdiots

Re: Really Descriptive Names

2007-11-07 10:24 • by ArashiNK (unregistered)
I'd rather have the long obnoxious name than the short uninformative one. Though actually, once in high school, I used the long obnoxious name in a programming class. The rest of my classmates stopped copying my code after that.

Re: Really Descriptive Names

2007-11-07 10:28 • by MET
160139 in reply to 160132
seymore15074:

I use vi. I would fall short of being very happy about it.

I also wouldn't be very happy about using vi. :)

(for those with sense of humour failure, I realise I have quoted without the context).

Re: Really Descriptive Names

2007-11-07 10:28 • by alexgieg (unregistered)
I didn't know German had such a huge influence in modern programming.

Re: Really Descriptive Names

2007-11-07 10:31 • by real_aardvark
160141 in reply to 160127
-j:
If it encourages code like that, intelisense is neither intelligent nor makes any sense. Probably heresay on a winforum like this :-(

Excellent mis-spelling: is that "hearsay" or "heresy"? It kinda makes sense either way...

Your point is sound, though: anybody defending this "Kingdom of the Nouns" approach because tools can understand it (after all, a tool wrote it) is either disingenuous or insane. Taking "Intellisense" as a case in point, what possible use could the auto-complete mechanism be in an environment like this?

The Intellisense goggles, they do nothing ...

Re: Really Descriptive Names

2007-11-07 10:33 • by Bosshog (unregistered)
160142 in reply to 160126
snoofle:
Jake:
Debugging a function with variables named a, a1, a2, a0, aO, al, a1l, al1, aIl, a1I, and al1I is something I wouldn't wish on my worst enemy.

I would!


Me too - I *hate* that goddamn buckingham.

Bigger is better!

2007-11-07 10:43 • by A.J. (unregistered)
It's only 94 characters long. The longest we have is 147 characters:
SubscribingSystemImplementationServiceIsSubscribingSystemImplementationServiceInDataSubscriptionContractSystemImplementationServiceDestination
and that's handily beating our second largest which has only 110 characters: DeliveryUniformResourceLocatorIsDeliveryAddressForDeliveryUnderDataSubscriptionContractEmailAddressDestination

Oh, did I already mentioned that we use model driven application developement? It's such a blessing (but to whom, I don't know).

A.J.

Re: Really Descriptive Names

2007-11-07 10:46 • by Mark (unregistered)
People, its simple.

a. We need to be descriptive, so hungarian is crap, but
b. We need to be succinct, so we need short names

Ergo: use namespaces, which are descriptive, but only appear at the top of the file (include/import) and then have short class and function names!

So.... ...ok I give up, I have absolutely no idea how you would break down this monstrosity of a name!

Re: Really Descriptive Names

2007-11-07 10:47 • by shadowman
160146 in reply to 160135
daniel c w:
I do not think it is a F.
Fail to see what's so bad about it.
I would actually write that kind of code.


p.s.: I do also not tink it is a W or a T


Is that supposed to be a malformed Haiku, or just bad poetry?

Re: Really Descriptive Names

2007-11-07 10:49 • by jkohen
160147 in reply to 160115
sweavo:
What language is that, that allows hyphens in identifiers?


English, among others. Presumably the hyphen is there to show us that the line was split for formatting.

Re: Really Descriptive Names

2007-11-07 10:51 • by rawsteak
DrugStrengthFormCountryManufacturerPharmacyCopayProductPriceFactory

is that DrugStrength FROM CountryManufacturer? I understand everyone has their own naming conventions, but at least spell it right! I had a friend who worked at a Chinese-owned database company working on the state's welfare system, and "October" was commonly referred to as "Octrober." She sometimes got errors in her code because of it!

Re: Really Descriptive Names

2007-11-07 10:54 • by Sam (unregistered)
160149 in reply to 160135
daniel c w:

I do not think it is a F.
Fail to see what's so bad about it.
I would actually write that kind of code

peopleIWouldPreferNeverToWorkWithBecauseTheyDoNotKnowHowToCode.add(new ProgrammerWhoDoesNotKnowHowToNameProgrammingElements("daniel c w"))

Re: Really Descriptive Names

2007-11-07 10:56 • by Fu King Ugli (unregistered)
I used to work on a pharmacy application that was eerily similar. Close to eight thousand classes all generated from some monstrous Rational Rose models. Jeeze, what verbose class and function names they used and those only grew longer when the classes were generated!

There were times I'd sit down in front of the computer and think I was looking at a strings dump or that Visual Studio had barfed garbage onto the screen then realize it was the actual code before me. It just all ran together.

Of course regenerating the basic classes was a breeze whenever the model changed but writing, editing, merging, or debugging additional code more than negated all the time savings. Fortunately for me our firm's contract was not renewed.

From what I understand the big pharma that hired us took one look at the code and trashed it all, throwing several million down the drain. Then they started over with a reasonable model with sensible naming and, though they also generated a lot of code, it was easily readable and editable.

Re: Really Descriptive Names

2007-11-07 10:59 • by Aaron
There are only two authoritative C# coding standards that I'm aware of, Microsoft's and Philips'. They both specify that for variables representing a generic instance of a class with unknown purpose, the correct name for the variable is the lowercase version of the class name.

Not "aThing". Not "theThing". Not "someThing". Not "myThing". Not "_thing". Not "iCanHasThing". Just "thing".

Furthermore, it's perfectly acceptable to declare a public property name identical to its type name. The .NET system classes do this frequently, for example, DateTime.DayOfWeek. This makes sense because, well, it makes sense. A date occurs on some day of the week, and a day of the week is... a day of the week.

There's absolutely nothing wrong with having a class named SecurityContext, and in another class, having a private field named securityContext, a public property named SecurityContext, and a constructor with argument SecurityContext securityContext. What else would you call the ctor argument - securityContextForThisInstanceButMaybeNotExclusively? Maybe securityContextThatHappensToBeUsedHere? Or perhaps securityContextUsedToInitializeAPrivateField"?

Silly prefixed versions like _securityContext or mySecurityContext add absolutely no new information and are therefore just useless cruft. The fact is, we have a class whose name specifies its purpose intrinsically; we don't *need* any more identifying information! It's not like an int, which could either be a record count or the current room temperature; it's a SecurityContext, which is... um... the security context. Duh?

Yes, this is illegal in VB. That's why VB and C# and every other language on the planet all have different coding conventions. But seriously folks, don't go around telling people how to code in their language based on conventions from your preferred language.

Capiche?

Re: Really Descriptive Names

2007-11-07 11:00 • by Anon (unregistered)
160152 in reply to 160110
Kharkov:
It reminds me of the naming conventions issued by IBM in the OS/2 programming documentation.

The only issue I ever had with this kind of descriptions was that the MS Pascal compiler truncated names after 64 characters, and to have function names differing only after this limit...


At least with OS/2 if you didn't know the API call name, you could pretty accurately predict what it would be.

Re: Really Descriptive Names

2007-11-07 11:02 • by chuck (unregistered)
What's really sad is how the ridiculously long class name is just a string of not-really-related nouns, signaling (to me anyway) that the class is likely to be just an aggregate of a bunch of data that doesn't really belong lumped together in one class. Yay for OO design :/

Re: Really Descriptive Names

2007-11-07 11:04 • by chuck (unregistered)
160157 in reply to 160148
rawsteak:
DrugStrengthFormCountryManufacturerPharmacyCopayProductPriceFactory

is that DrugStrength FROM CountryManufacturer?


What is a country manufacturer doing messing with drug strengths anyway? They should be sticking with what they know: manufacturing countries.

Re: Really Descriptive Names

2007-11-07 11:05 • by Nelle (unregistered)
160158 in reply to 160117
poochner:
Jens:
Jens:
And the variable names he passed are cool too:

SecurityContext and securityContext differ only in the capitalisation of first letter..

Brilliant !!!



oh ok, I just realised that it was the classname and the variablename that differ in first letter.. still not a bright thing to do..

It's very common, though, in the case where the argument would simply be "some generic instance of this class." Better than "temp" or (God help us) "arg0".


oh the eclipse ...

Re: Really Descriptive Names

2007-11-07 11:06 • by Tim (unregistered)
they probably put everything in the same package too. Packages would make this quite somewhat decent. I'm always amazed by the number of people who don't use packages to as part of a classes "name".


drugstrength.forms.country.manufacturer.pharmacycopay.ProductPriceFactory

Re: Really Descriptive Names

2007-11-07 11:10 • by Sam (unregistered)

class DrugStrengthFormCountryManufacturerPharmacyCopayProductPriceFactory
{

public DrugStrengthFormCountryManufacturerPharmacyCopayProductPrice
getSalesOrderProductSupplierCopayDrugStrengthFormCountryManufacturer-
PharmacyCopayProductPrice (SecurityContext securityContext,
SalesOrderProductSupplier salesOrderProductSupplier,
Organization copay)


I would love to take a stab at what this does.
My guess is that the class itself represents different ways to get Drug Strength Forms. (Hence the java convention of DrugStrengthForm...Factory.) Information in the DrugStrengthForm includes the following bits of information: Country, Manufacturer, Pharmacy, Copay, Product, Price. (Or maybe just country manufacturer, pharmacy, copay, and product price. Isn't collocation fun?) Who knows why they would put this information in the class name?

One way to get a Drug Strength Form is by the combination of a SecurityContext, a SalesOrderProductSupplier, and an Organization object (named copay for some reason). The Sales Order contains a Product and a Supplier (or just a "Product Supplier.")

But it's a poor naming convention at best. If I want to know what's in a class, I can look at the darn definition or even use (ick) introspection. Hell, if they are using Java beans or annotations, this is pretty damn simple. If they have different DrugStrengthForms with different bits of information, have a class that returns "null" for bits of information that aren't available.

Imagine if the code looked like this:

class DrugStrengthFactory {

public DrugStrength getBySale(SecurityContext securityContext, Sale sale, Org org) {[...]}
}
class DrugStrength {
public Country getCountry()[...]
}
[...]
DrugStrengthFactory drugStrengthFactory = new DrugStrengthFactory();
drugStrength = drugStrengthFactory.getBySale([...]);

And I still think the class names are a little too long in my example....

Re: Really Descriptive Names

2007-11-07 11:13 • by Nutmeg Programmer (unregistered)
CIRCA 1974, a co-worker ported a payroll system from COBOL to Data General Fortran. Although the compiler would accept 32 character variable names, they had to be unique within the first 24 (IIRC). Obviously, we were not using punch cards.

It was a real shock to go back to IBM Foratran IV and 6 char variable names at my next employer.
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment