- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
And there was evening, and there was mourning—the third normal form.
Admin
Dan, don't try to imitate Erik.
Admin
I liked the bit where the perpetrator got lynched by an unruly mob at the end.
captcha: abigo
O
Admin
And what's the problem?
Admin
It hurts.
Admin
Hey, those look just like the method names I see in Java!
tbh, I never understood why so many people dislike long variable names.
Admin
AutomationExportAutomationExportFieldLUByAutomationExportID = GetAutomationExportAutomationExportFieldLUByAutomationExportID(AutomationExportAutomationExportFieldLUByAutomationExportIDToRetrieveId);
More clear now?
Admin
Note: Everything depends on the definition of "Long".
While very short, the following line would be even worse:
x = f(y);
My approach is:
If you can't get the functionality of a line with a single glance you either have
Admin
And has anyone noticed that we are back to the frist normal form of supplying comments to TDWTF articles.
Change is never a good thing
Admin
However, when the length of the variable name and the length of the method name each are above, say, 40 characters, the code tends to become a tad bit unreadable.
Admin
Pssh, that's nothing. In a project I work with we have the same three laws of progotics, which has lead to a table called "ProjectDisciplineProjectDocGenTypeFormatDocRevisionMetaField" which, naturally, has a stored procedure named "spProjectDisciplineProjectDocGenTypeFormatDocRevisionMetaField_GetByProjectDisciplineProjectDocGenTypeFormatID"
Admin
At least they're not running an Oracle database.
Admin
Another reason could be that CS allows him to show BuildMaster ads to us; something Discourse doesn't seem to support (at least there aren't any yet).
Admin
I think the rules are ok. I can see the advantage when you can sort by table name when having dozens of stored procedures for each of your dozens of tables.
But if you apply the rule to bad table names and fields, then not the rule is guilty, but the bad table name and their fields. Usually, the table name should not be repeated in the name of the table fields. This is bad:
Table: AutomationExport fields: AutomationExportFieldLUB, AutomationExportID
So correct it by renaming fields to: FieldLUB, ID
Now applying the rule: GetAutomationExportFieldLUBByID
By the way, what's the meaning of "FieldLUB"? If a "LUB" is a company-known acronym, then it is better to name it "Lub". The same goes for "Id". If there is no other type of LUBs than a "field"-LUB, you can omit the word "field". That gives us:
Table: AutomationExport fields: Lub, Id
Now applying the rule: GetAutomationExportLubById
I would refine the rule: if there are more than 2 fields returned then you can give a goup name instead: Example: employee-table that holds first name, middle name, last name, street, city, country, zip, status, salary, ID, and you want to retrieve all the address data, then you can use: getEmployeeAddressById or getEmployeeFullNameById instead of: getEmployeeFirstNameMiddleNameLastNameById or getEmployeeStreetCityCountryZipById.
You can also split up the employee table and put the name data in a second table. tableName: employeeName fields: first, middle, last, maiden, title, ID
Now you can access by: getEmployeeNameFirstLastById
This way you can say: if the stored procedure name gets too long, you have a bad table design!
Admin
If it is an abbreviation, then Mixed case. If it is an Acronym the Upper Case. Some words start out as acronyms, but are later recognized as words (SCUBA/Scuba being perhaps the most common).
Admin
the Microsoft standard is that acronyms and initialisms are treated as words, that is lowercase with a leading capital where appropriate. i use it because i find that PcmciaCode is more readable than PCMCIACode.
hmm. what if FieldLub is used elsewhere in the system? or if the field is "Account" and the table "Bank"? how do you differentiate Bank.Account from Wtf.Account? doesn't that break Nth normal form?
Admin
Have you ever read the story "Goldilocks and the Three Bears"...?
Admin
Radar, Modem, ... I'm sure there are more
Admin
Are you guys just trying to troll your regulars into non-existence?
Admin
The practice seems oddly German.
Admin
Captcha: usitas - chaining nouns is not in widespread usitas.
Admin
Sup dawg, I heard you like AutomationExport
Admin
Long variable names are harder to remember/type but can follow a pattern to compensate. The problem is you really need to adhere to this pattern well. Having a pattern makes thing predictable, organisable, easier to automate, and so on. If you can remember rules for naming you can use this to work out what names refer to/could be if you read/are writing them. Actually this is often not possible if you let a human choose what they believe is linguistically optimum each time. You cannot necessarily anticipate as easily this way. Consistency might give you a better heuristic.
Naming tables well can be very difficult. This is one way to compensate, it can more often be clear what to name certain complex tables that don't quite represent one thing. For example, you might decide to call your intersection tables TableATableBRelationship. We might have a lot of words for each thing but words for relationships between things are tricky. It's not always the case a single word can represent the whole relationship between the pair (and the relationship type) or even the pair.
This kind of pattern is also useful because it can make a kind of a stronger contract between function name and what a function does. However it doesn't work well for weird cases.
I've used this same pattern in an automated sql model builder. There's a bit of a difference between asking a human to do it and a machine but generally my rules for humans. For a human finding good names is one thing, but for a machine, just give it up. For my automodel this works brilliantly and by functions look a lot like the above. Although it outputs function names, it's enough for me to know the table structures because the consistent naming convention creates a direct mapping to these.
I don't have names as long as:
GetAutomationExportAutomationExportFieldLUByAutomationExportID though. I expect there to be rules for making exceptions or aliases where names become too long. Those cases warrant some extra time to think about an effective name. Still, I have inherited legacy code with one function that was more than 100 characters long describing everything it did in detail (ie get_user_from_database_where_id_is_user_id_or_return_null_etc). Perhaps frustration caused him to do this or otherwise he thought it a clever way to not Doc the function.
Apart from that I think the developer in the article really isn't that bad. He looks like he's ahead as most projects have no naming convention at all. Overly strict enforcement might be a problem. He could be tired of people trying to give a short concise names to functionality and making the situation worse. I have seen people sit there for an hour working out what to name a function or variable.
I have many such rules and I am quite strict. I use _ rather than camel case in my DB structure, prefix tables, yet do not have table names more than 40 characters. I think the longest few are a bit over 30. In the code, I don't thing there are many functions much more than 20 characters.
Summary...
This discussion belongs under why human language sucks category.
Admin
Admin
argg
Admin
Address can have only country, so what the purpose in AddressCountryTable table?
Admin
Nothing in the article is remotely related to normalizing.
But let's consider an example where some asshole decides, "let's denormalize these tables for speed."
Then a simple "INSERT (serial, widget, color) VALUES (?, ?, ?)" becomes five or six insertions into various places.
And there are odd bugs due to race conditions that languish on the bug tracker. So users waste huge amounts of time with workarounds.
And you can't express the internal constraints with a few foreign keys, so it's all enforced throughout the application.
Thus refactoring code becomes an arduous process of fixing copy-pasta, generating more bugs, fixing those, etc.
But you got rid of a table or two on the schema diagram, so it must be simpler! And practical!
Admin
I'm sure there's a typo in there, but I can't find it again to tell you where it is.
Admin
lead vs. led
Admin
Heaven help the person that tries some recursive linking/references
Admin
Cannot agree more with this one.
Given a human had hard time to understand more than seven things at a time, have seven different words in an identifier is overboard.
Names are ultimately abstraction of what the table/procedure does, it is okay to summarize, going overboard with naming convention to provide information reminds me of Hungarian notation which I hate.
What is m_pptm? A member variable which is a pointer to pointer of the transaction manager ... kill me with that one.
Admin
Were there priests involved?
Admin
I kind of like long variable name if it is not too long.
I guess this depends on how wide your screen is, if you need to scroll that is definitely not good.
I use a simple heuristic called printing test. If I could print to code on a paper in landscape mode without having to wrap the line, it is probably not too long.
Admin
As a number of people already have said, verbosity in itself isn't a bad thing. Especially these days when you have an IDE to do most of the work for you (completion etc). Sure, there's a limit to when it becomes ridiculous, but the point of the article seems to be that having a naming scheme that may lead to long names is bad. I disagree. (Since it is databases involved, perhaps there's some domain-specific thing why verbosity is bad. I don't know the first thing about databases; my comment is more general with code development)
Admin
Admin
Admin
com.sun.java.swing.plaf.nimbus.InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState
Admin
Admin
Admin
Of course, Oracle has a 32-character object name limit.
Admin
Sometimes it is useful to have long file names and avoid developers groping in the dark to find the right function for the job.
Admin
Admin
I beg to differ.
Verbosity in itself is a bad thing, and typing effort is the least of the reasons. It makes code harder to read and understand, variables more difficult to recognize and distinguish. Any naming convention forcing long names must make up for these costs.
The best names are short, concise and descriptive. Long, descriptive names may be better than non-descriptive names of any length, but they are still a compromise.
Admin
Hmm. The English standard is to capitalize the first word of sentences, but, you know, to each his own.
(As a rule, I detest comments which mention the captcha (including this one), but my captcha was "conventio" -- just too apropos to ignore. Sorry. Yes, I am.)
Admin
This is just another case of the old axiom - There are only two hard things in Computer Science: cache invalidation and naming things.
Admin
So, if you change the name of the foreign key, add/remove a foreign key, you have to change the name of the table??
Admin
Well, there's your problem: you got the axes backwards. Everyone knows that y= f(x), so x = finverse(y)
Admin
What happens if there are multiple foreign keys in the table?
Admin
That line is extremely easy to understand.
Try something like this:
Admin
I always use as much FieldLube as possible.
As a rule, I detest replies to comments (including this one), but the comment to which I am replying was just to apropos to ignore.