- Feature Articles
-
CodeSOD
- Most Recent Articles
- A Sudden Tern
- Going Through Time
- A Pirate's Confession
- The Review
- No Yes
- The Utils
- A Case of Old Code
- Linguistic Perls
-
Error'd
- Most Recent Articles
- Twofers
- Two-faced
- Boxing Day Math
- Michael's Holiday Snaps
- Anonymice
- A Horse With No Name
- On the Dark Side
- Untimely
-
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
Edit Admin
While we're bitching about names ...
The class name of the parameter object named
orderisCreateOrderRequest. When you're naming your objects which represent nouns using verb phrases, there's something damaged between your ears.And what business item does that object represent? An order, a request, a request to create an order? Whatever it is,
orderis almost certainly a bad name for a parameter representing one of them.Admin
I very much dislike ternaries. They always strike me as a developer-being-oh-so-clever thing. I'd much rather have them split out as an if-else so that their meaning is absolutely clear to whichever poor soul has to look at the code in the future.
Edit Admin
The thing I dislike about ternaries is the scope for showing off your ability to be cryptic and lazy at the same time.
Case in point, this sample I found in a codebase almost 30 years ago (and the context is important...):
Too lazy to put braces around the inner if() ???
Admin
Plus the fact that order.GetOrderParams() is called three times, two of which use .getOrderType() on the result.
Edit Admin
Sure it's not short for
ORDURE?Edit Admin
+1 for spelled out if else then. My brain does not parse code like from the tape of a turing machine, but sees the pattern/structure like Ifs.
Admin
Ah, the constant name things, they're fixed width fields, dating back to when the data entry was done with punched cards.
Edit Admin
The abbreviations could be from another system, so you could recognize where the values came from.
Edit Admin
Almost certainly a
CreateOrderHTTP request. Do you have a better suggestion for what to name the class? Sometimes there are no good options, so you go with what you think is the least bad. See also the second hard problem in computer science.Admin
I'm not too bothered by ternaries, if they're not trying to be "clever". Simple statements for assignments or returns are convenient, especially in places where a whole if/else construct would actually hinder readability. But I was happy when C# added the null-conditional and null-coalescing operators, to eliminate an entire class of these things.
Edit Admin
It really can't be that much more work to write this instead:
Admin
Your complaint kind of makes sense in a vacuum. But it ignores the fact that any sufficiently complex system is going to naturally develop a set of conventions, written or implied that dictate the patterns used to name things. So whilst this might be ambiguous to you without the context of the system it is written for anyone familiar with said system will most likely have no ambiguity at all as to how to interpret it.
Edit Admin
I agree with what many of you say about ternaries in general, especially in the wild, but I do feel they can have a place, especially when each operand is short:
Though I also like @dpm's approach above.
Addendum 2026-01-15 11:04: Probably should have put
var orderTypeCode = ...abovevar companyFoo = ...Admin
Ternaries need to be used if you are initializing a read-only variable whose value depends on a condition. Also, I find this formatting for nested ternaries to be pretty readable:
var x = condition1 ? value1 : condition2 ? value2 : condition3 ? value3 : value4;Edit Admin
So, Remy, you're not a fan of disemvoweling words?
Admin
Why not write conditionals that wrap across three lines, so long as you do wrap them?
Aversion to conditionals is a solid mark of a timid developer.
Admin
If that was the case, I don't think it would have been submitted to this site in the first place.
Edit Admin
@dpm I like a lot of what you did there. but it amounts to this pattern that's notso hotso
I agree it's nice to avoid syntactic negation in the predicate of the if. But if the result of doing that is semantic negation spread across several lines all of whic are assuming the special case is the common case, I think we threw out the baby and saved the water. In your case we ended up with both. IMO much better to always arrange this pattern like
This latter form also extends neatly if there are multiple special cases, whereas the former does not.