- 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
Admin
And on Rupert's frist day at the office in his new company, he's invited into the special high-intensity think group to help debug this code which has baffled the top minds of the company:
"We can't understand what's wrong. Whenever we run it, we get a stack overflow error. Any insights, being the world-class coder that you are?"
Admin
This wtf is bigger than Rupert. It's the lonesome-hero model of engineering. It may be true that some programmers are 10x more productive in a particular day's work than others. But world-class programmers? There are ten of them. Chances are you and I are not among them. Let's get back to work!
Admin
Lovely, lovely. I just think he named the methods incorrectly. It says "get street", whereas it's clear the method returns the provided street. So it should be named "returnTheSameStreet". Then, the naming matches the function, and we can all see that it's bulletproof and will pass any testing you through at it. It becomes world class code!
Admin
Ahhh. but what could derived classes do with them... Side note, designing for derivation is HARD. Writing your base class so that unknown programmers can use it effectively as a base class - and still guarantee that their classes will not break your contract takes LOTS of work.
Admin
Team Lead: You can't hard-code values, you have to populate them through a method.
Rupert: Stand back and marvel people!
Admin
Unsurprising. As soon as anyone considers themself "world class" to the extent they feel the need to tell everyone else about it on a regular basis, you can basically guarantee that they'll be average at best, and most likely produce the kind of rubbish shown here. I assume it's related to the Dunning Kruger effect, as well as the fact that people who have that sort of opinion of themselves obviously see no need to listen to others' criticisms of their work!
Admin
Let's give this world-class programmer just a little credit. The code has potential for easily adding some useful extra functionality. For example, the call getCity("LA") could be configured to return "Los Angeles", and so on.
Admin
Why was there no code review to mention this, no pull request to decline?
Admin
Are you Rupert?
Admin
Thanks, Bro, for this great recommendation of the most perfectest world-class coding style! I'll hurry on to introduce it in my team. I am sure that Kevin will enjoy it.
Admin
But most of the time, the base and derived classes are part of the same codebase, so new parent properties/methods can be added as needed rather than trying to predict the future up front. Or as is frequently the case in my company, just take the functions that have been copy-pasted into half a dozen classes and refactor them into (or create) the base.
Admin
Well, at least he didn't cast and re-cast into and out of some "proprietary" encryption nonsense...
Admin
Have you ever worked with a Rupert? If his company instituted code review, Rupert would immediately come to the conclusion that the entire world was out to ruin his reputation by logging trivial code review rebukes. His "ironclad proof" would be the fact that the product does not exhibit a demonstrable bug.
Then, everyone would be sent to sensitivity training, and a director would sit in on all future code reviews to ensure that no one ever criticized anyone else's work, ever.
Admin
Actually I believe the perfectly cromulent naming convention, given generics, would be:
The great thing about this is that it allows for overloads and side effects, should you need them in the future. Which in this code base I assume you would.
Admin
Nah. They're usually a sign that I've had my sixth cup of coffee a bit too early in the day.
Admin
"Oh that's so obvious, you are supposed to pass the value by parameter and then return it! See? This is why you need a world class programmer like me! Can we discuss my raise now?"
Admin
|Let's give this world-class programmer just a little credit. The code has potential for easily adding some useful extra functionality. For example, the call getCity("LA") could be configured to return "Los Angeles", and so on.
That was my first thought--this is either to allow for future data massaging (and maybe even present massaging---the functions that actually do something might not have been included because they aren't WTFs) or the remains of past data massaging.
If it were truly a WTF to support this we wouldn't see c# supporting {get; set;} declarations.
Admin
He learned long ago that global variables are wrong, you should use parameters and return values.
Admin
One minor detail and I hate to be nitpicky like this: the original code had the method decorated as "protected", whereas yours is "public". Our world class programmer took care of security, too!
Admin
As TheCPUWizard hinted at, couldn't these methods actually serve some useful purpose in an abstract baseclass? Derived classes could override them to implement validation or transformations of the various fields.
Admin
Darn, I missed that.
I am no longer world class. I might even struggle to be small continent class.
Admin
Now, to be absolutely fair, this is a very good example of "fixed point theory" in practice.
Not an especially useful one. But you can't deny that it is a wonderful way to describe a fixed point, within the functional domain, by mapping the point onto itself.
Admin
(a) Hide your globals private to some scope. (b) Return pointers to the through a function. (c) Enjoy the pain of having globals, but now they even have different names i each function that accesses them.
Addendum 2021-06-02 17:44: *to the globals. Autocorrect on my iPad recently likes to eat words.
Admin
I feel like "world-class coder" is the kind of title programmers assume for themselves the first time they break through a bottleneck of understanding and start to see beyond the code. Their eyes have been opened for the first time, and they naturally assume everyone else's eyes are closed, just as theirs were a moment before. Relative to where they were, it really is the difference between the heavens and the earth... but there are many more such moments to come.
Admin
It HAS potential, doesn't it:
protected function getCity($city) { if (cityService.countPubs($city) < 10) { throw new BoringCityException(); } if (cityService.isDictatorship($city)) { throw new YouDontWantToGoThereException(); } return cityService.translate($city, getMyLocale()); }
Addendum 2021-06-03 03:54: It HAS potential, doesn't it:
Admin
That would leave the issue of getCity being a bad name for the functionality. I struggle to think of a good name for it though, which is probably a bad sign.
Admin
Don't throw unexpected Exceptions from your subclasses!
Admin
I'm surprised nobody has picked up on this application of our study about this. Rupert was our inspiration for our theory that some people are so clueless that they can't even understand the fact that they are clueless.
Admin
You're absolutely right that somebody claiming to be a top-notch programmer should be immediately suspect.
I remember when I encountered one such "brillant" programmer who checked in code he claimed was production-ready, but he'd fouled up enough times that I was being asked to QA stuff before we pushed it live. So I did, and immediately encountered his syntax error on code he'd wanted to be on our live servers right away. In my conversation with the head of development, who had up until now been generally supportive of this guy, I noted that if he'd gone so far as to actually run his code before sending it, he would have found this problem immediately.
He was fired soon afterwords.
Admin
It would be nice if "comments held for moderation" would be showed in the sequence at the time they were allowed through, not at the time they were posted :/ Hard to find comments I missed that way.
Admin
Its the same in many languages that instance variables can be accessed, they are just another scope level. C++ and C# allows the same.
In C# you can use this prefix to distinguish between a local variable or function argument and an instance variable, but it is not required.
Admin
World class apparently means averaging out the programming ability of the entire global population.
Admin
Sometimes "I don't know how to do this" constitutes higher ability than trying.
Admin
a few years ago i worked on some legacy code written in C - original code used "structs" to describe sound and graphic data and set of access funcions to control playback, modify graphic and so on. At some point project structure changed - some asset were moved to "display server process" and all access functions modified to automatically recognise remote assets and and use interprocess communication instead of manipulating local variables. Migration SHOULD be quick and easy since clients call convention didn't change at all - except some programmers didn't use access functions, cause "it only modifies one member variable anyway"... Finding and fixing "optimised" staments in 100's of legacy modules was not fun.
Admin
We had a world class programmer at a company I worked for once. When he quit, he refused to tell anyone where he had gotten a new job, because, he said. He didn't want anyone at his current job calling the new place and badmouthing him. Why would we do that?, I asked. If we convinced them to rescind the job offer, you'd stay here.
Admin
Ah, I see the problem. Clearly a more enterprises solution would be to write:
Private String getAnything(String anything) {Return anything;}
Public String getCity(String city) {Return getAnything(city);}
Public String getStreet(String street) {Return getAnything(street);}
Etc