- 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
I once worked with someone like that, but never asked. There are times when I feel I need to distinguish some central object undergoing some transformation and "the" then seems like an option. However, most times, a better name can be found or is actually not necessary after all.
Edit Admin
Waay back when I was first learning tht new-fangled OO stuff, I'd encounter lines like
List list - new List ; declare a shiny new ListAnd it would really mess with my head. Because I was just transitioning from pe-OO languages that were case insensitive, or more accurately from languages and input systems that were all UPPERCASE.
So a) I wasn't used to even noticing the casing of words, and b) the idea of variable named the same as their type just felt dangerously ambiguous.
Mostly separate comment:
All around codebases and many tutorials we see stuff like:
List mylist - new List ; declare a shiny new ListThe use of "my" is common. And pretty dumb. IMO using "the" prefix is just an idiosyncratic form of "my". And both stem from a reluctance to name a limited scope variable the same as its underlying type.
Addendum 2025-12-09 06:55: Sorry about the typos in my code samples. they were supposed to be on separate lines below the leadup sentence. And the hyphen should be an equals.
Admin
It's often seemed to me that distinguishing the variable from the type solely by the capitalisation of the first letter is really just a highly specialised form of Hungarian notation
Admin
Back in '94 ESRI released a new scripting language, Avenue, for their cross platform desktop/GUI GIS application, ArcView 2. The underlying system and API were object-oriented , but the scripting language didn't allow for creating new classes. This was the coding style ESRI promulgated to its users, most of whom were geographers, statisticians, etc., not developers. Avenue stuck around through ArcView 3 and was in use well into the oughts, but when ESRI transitioned all of their desktop/workstation applications to a new architecture, they replaced Avenue with Python. You can see some samples of this style of coding from this 1999 ESRI international users group conference paper: https://proceedings.esri.com/library/userconf/proc99/proceed/papers/pap585/p585.htm
Admin
If you want a viable use case for a “map of lists,” I do it quite often with line items and grouping them by parent. I probably have a few other uses, but I’m on PTO, so I’m not gonna look!
Edit Admin
I once worked with an off-shore developer from an English speaking country. If I told him "create a fiunction that takes in the map, the key, and the value; it should make sure to add the value to a list in the map using the key. If the list doesn't exist, ensure to create it first." This is what you get.
Admin
I have seen code that uses "theSomething" style a lot, which had an 80s Mac origin, and the use of "mySomething" from developers with lots of Perl experience. Without knowing any better, why not use what you know?
Edit Admin
I've also seen that style and felt the red-hot burn of hate every time.
Edit Admin
As I recall, Smalltalk 80 had a style where the method name would imply the meaning of the parameters, but the types were essentially indicated with "aString" convention. So something like "someString concat: aString". Can't remember what happens if you have two params of the same type.
Admin
I worked in a large code base that used the
theprefix to denote global singleton objects. Most of the time variables were named normally, but if you ever saw something namedtheFoo, you knew it was the only instance of aFooin existence.Edit Admin
theFristKey,theSecnodKey, etc.Admin
Pretty sure the insistence on THE applies only to the full name, The Ohio State University, but people do say just Ohio State without problem. Yeah?
Admin
VBA features Case Sensitivity Done Right: the language is case-insensitive, but the IDE forces consistent casing, so that you type the correct case when you define an identifier, and then afterwards you don't need to trouble the shift key and the IDE corrects it for you. (This is a side effect of the IDE tokenising everything as you type.)
The downside is that if you want a scratch variable, you can't call it list but have to resort to something like theList or (even worse) lst.
Edit Admin
I have used "my" in a few rare circumstances where I am explicitly producing something of my own that is in contrast to something else more standard. Random example, monkey patching (shudder).
Admin
I feel like this is someone like me who loathes types and instances that differ only by capitalization, but they have to work with coding standards that distinguish types from instances by capitalization. Hence they put "the" in front of instances. I would much, much prefer to deal with Map theMap than Map map.
Admin
Yes, this is common convention in Smalltalk. e.g. "aString" or "theString". Mainly just if you can't think of a better name, and of course it would be a crime to name instance variables this way, you'd only use this for method parameter names (where Smalltalk uses keyword names in the method so the actual variable name is less important) or local variables.
Edit Admin
"The Dark, The Sword, The Forsaken, The Temple"
Admin
I think, variable nameing is overrated.
On the one hand, the shown problem mostly arises in generic code where you add a generic value to a list of other values you know nothing about. So you can't give funky names, which convey meaning, to things. I would simply call the list
l, the keykand the valuev. Done. Yeah. Yeah. I know: single letter variables names. shock horror worldstopsturning But who cares? You still get what they mean and the function is so small that you can easily identify the context should there any be confusion. I'm also a mathematician by education. I'm used to single letter identifiers. If need be from foreign alphabets as well.If context becomes more complex despite all efforts to avoid it, I would still use
lstinstead oflist. Why? Because there is a functionlist, which I don't want to shadow. Even if I don't use it, it is confusing. And when you decide to use it later on, you can get easily in trouble. EntertheListfrom the left.There is always context: the problem domain, the programming language, your background.
Which brings us to other hand: Just be consistent. Pick one style and stick to it. Consistency is the key here. Pick your rules. Follow them. Be done. If you come fresh into the project, learn the rules. Follow them. Be done. If you think a convention sucks, that's fine. I also find conventions, which tie variable names to types, really dumb. Still follow it, if it's the project way of doing things. Consistency lowers the cognitive load. And that is priceless.
Admin
Regarding map of lists...
At the moment I work with a list of maps, which map one key to a label and another key to a list of maps, which again map one key to a reference id and another key to a predicate definition which is again a map and maps operations to reference values. This structure comes straight from the business side of things and is translated into a function over a dataset, which applies the predicate definitions to the referenced data points. if all predicates are true, we'll attach the label to the thing which gave rise to the dataset.
You ask about the types and generics? Dunno. Don't care. They are not relevant for the problem.
Edit Admin
theForum.post(theComment); theForum.append(theSigLine);
Admin
Hm.... Looks like a variation of The HashMap. B-)
Edit Admin
I'm surprised it's not obvious:
theFristKey,theSecnodKey. Much better. It's scaleable too.theThridKeyEdit Admin
I call it "wart-only Hungarian" ("wart", of course, refers to the type-information (Systems HN) or flavour-information (Applications HN) prefix).
Admin
Hardly "specialised Hungarian" its the difference between a proper noun and a common noun.
Edit Admin
"This is a side effect of the IDE tokenising everything as you type" I'm reminded of a glitch in BASIC (interpreted) where the line 'IF TAN D = 0 THEN ..." Would throw a syntax error. If you typed it in with spaces, like "I F T A N D = 0 THEN ..." It'd think you were typing "IF T AND = 0 THEN ..."