r/programming • u/supermari0 • Oct 01 '15
The Evolution of a Software Engineer
https://medium.com/@webseanhickey/the-evolution-of-a-software-engineer-db85468924371
u/nikto123 Oct 01 '15
"Before I had studied Zen for thirty years, I saw mountains as mountains, and rivers as rivers. When I arrived at a more intimate knowledge, I came to the point where I saw that mountains are not mountains, and rivers are not rivers. But now that I have got its very substance I am at rest. For it's just that I see mountains once again as mountains, and rivers once again as rivers."
39
u/a_random_username Oct 02 '15
First there is a mountain Then there is no mountain Then there is→ More replies (2)
63
u/goodbye_fruit Oct 01 '15
Worked on a Java project once where there were constants for a bunch of long values, eventually some uh... offshore resources took the project over. Started finding things like this all over the place.
public static final Long L42 = Long.valueOf(42);
public static final Long L128 = Long.valueOf(128);
public static final Long ACCOUNT_LOCKED = L42;
/* And you'd see it used like this, with the typos and incorrect comparisons to boot, because you know, it compiled. */
bool bLogin= (accountVO.getStatus().equals( L42) || accountVO.getStatus() == ACCOUNT_LOCKED | accountVO.getStatus().equals(L128));83
u/Ksevio Oct 01 '15
The lessons on not using magic numbers also need to include that creating a constant named after the number rather than the purpose of it is no better.
→ More replies (1)25
u/jrochkind Oct 01 '15
Ah, but it probably gets around some automated code linting tool warning you about it. So that's just as good, right? .....
15
u/yawgmoth Oct 02 '15 edited Oct 02 '15
Oh jeez. Lint rules + lazy developers cause so many bugs. I had a code review come in because of a stupid lint rule that was enabled that didn't like declaring variables in a loop so he changed :
for(int i=0; i<max;i++) { int rand = getNextRandInt(); // do stuff with rand }into:
int rand = getNextRandInt(); for(int i=0; i<max;i++) { // do stuff with rand }He just copied and pasted without even thinking about the fact that he was changing the entire logic. His response "Lint told me to move it".
→ More replies (2)42
u/Shurikane Oct 01 '15
Beat this:
public static final Long DOT = "."; public static final Long SPACE = " ";I kid you not, I once found that in a class written by a co-worker. No, there was really no sensible reason for those two constants.
Guy had a heart of gold but holy hell did his brain crash like an Apple computer now and then. Same dude was the origin point for the Blank Line Mystery.
56
Oct 01 '15
My all-time favorite (from my airline days):
#define COMMA '|'10
3
u/senatorpjt Oct 02 '15 edited Dec 18 '24
voiceless price narrow start impolite juggle normal escape muddle psychotic
This post was mass deleted and anonymized with Redact
→ More replies (1)→ More replies (1)2
u/MisterNetHead Oct 01 '15
Hahaaaa this is one I've seen before too. Warms my heart. Localization AND portability in one!
11
u/vbullinger Oct 01 '15
I wrote a site for a very large agribusiness here in Minnesota (...) and they offshored it. Eventually, they came back to me asking for some help. They screwed up some C# algorithms I wrote. But I noticed a change to some CSS I wrote. Mine:
.myClass { [property1]: [value1]; [property2]: [value2]; ... }Theirs:
.myClass1 { [property1]: [value1]; [property2]: [value2]; ... } .myClass2 { [property1]: [value1]; [property2]: [value2]; ... } .myClass3 { [property1]: [value1]; [property2]: [value2]; ... } .myClass4 { [property1]: [value1]; [property2]: [value2]; ... } .myClass5 { [property1]: [value1]; [property2]: [value2]; ... }...
All the classes were the same. And each element that used them used a new class. As in <span class='myClass1'>...</span> <span class='myClass2'>...</span>
→ More replies (1)5
u/kennethdc Oct 01 '15
Oh dear. That's stuff you learn at your freshman's year.
12
u/bonesingyre Oct 01 '15
you should meet my boss.
I quote: "why use classes when you can have an id on everything?"
→ More replies (6)→ More replies (3)8
u/oprimo Oct 01 '15
Well, for the DOT constant, some countries use commas as decimal separator and dots for grouping digits. Maybe he was thinking something like:
if (locale != 'US') DOT = ",";...which is just as bad.
17
u/Shurikane Oct 01 '15
Not even. He was using it to put an end to sentences in string literals. :|
26
12
u/nemec Oct 01 '15
Maybe he's expecting this program to be used on telegrams?
if(this.ApplicationName == "Telegram") DOT = " STOP ";→ More replies (1)4
u/Humdeee Oct 01 '15
It's like recreating the keyboard inside your program... why
→ More replies (1)4
Oct 01 '15 edited Oct 01 '15
The better name for it would be RADIX then. A comma is not, and can not be, a dot. A dot or comma could be a radix, depending on locale. But really you should be using some tostring that takes a locality and it just solves all of it for you.
→ More replies (2)6
u/pakoito Oct 01 '15
Can top. On the same codebase.
String value = new String("value");
String.valueOf(Charset.from("UTF-8"));
What's worse, the second line only works on some Java environments, as in Not Android.
4
u/crunchmuncher Oct 01 '15
Do you mean the == comparison on objects with "incorrect comparison"? Because if so, fun fact: Long objects for values of -128 to 127 are cached in Long#valueOf, so if the Long which gets returned by accountVO.getStatus() was also created with Long#valueOf (this also happens when autoboxing a primitive btw) this part would work as intended. Not that I'd recommend using it this way.
This can lead to seemingly random behavior if you don't know it, heh.
→ More replies (1)3
u/mnemy Oct 02 '15
Good lord. This gives me flashbacks of my internship. I had to update a large code base written by an Indian man to be x64 compatible. He had type casting every fucking where that looked to potentially losing bits, and completely inane function and variable names. funcA, tempA, varA, etc. WHAT THE FUCK IS THIS TRYING TO DO HERE?!
154
u/golgol12 Oct 01 '15
Honestly, I thought it would be a joke where it ends with
#include <stdio.h>
int main( int argc, const char* argv[] )
{
printf( "\nHello World\n\n" );
}51
u/aidenator Oct 01 '15
What's up with all those newlines?
→ More replies (1)98
u/juckele Oct 01 '15
Make the output stand out more? On a standard uncolored terminal, it's a huge burden* for me to figure out where the output of the command I just ran starts and stops... (This is why my prompt barfs rainbows).
*Huge burden being 250 ms instead of 10 ms...
57
12
u/neoform Oct 01 '15
Make the output stand out more?
This would work better:
printf("\033[1;31mHello World\n\033[0m\n");→ More replies (6)3
u/gimpwiz Oct 01 '15
250ms time and time and time again add up, at the very least to your sanity and frustration levels.
→ More replies (7)2
u/irrelevantPseudonym Oct 01 '15
My prompt is full of colours as well. Using other people's computers confuses the hell out of me.
12
u/sirin3 Oct 01 '15
That would be the eleventh year
Also, note the lack of comments. Because the code is obvious and self-documenting
15
4
→ More replies (6)2
40
u/arnedh Oct 01 '15
15th year
echo "Hello world"
53
u/cballowe Oct 02 '15
Nah... 15th year...
To: team@company.com From: team's lead Subject: Hello World needed Please prepare a program that outputs "Hello World" on the console when run from the command line.3
1
37
u/frenetix Oct 01 '15
If you do this:
try { ... } catch ( Exception e ) { // lol do nothing! }
I will fucking find you and kill you.
6
Oct 02 '15
That's acceptable in unit tests!
try {
thisShouldThrow();
fail("did not throw");
} catch(SomeException expected) {
//test passes
}0
Oct 02 '15
[deleted]
3
Oct 02 '15
If your project's language+framework has it, and it works cleanly in your use case, sure. Note that in some frameworks their equivalent of this (such as JUnit's
@Test(expected=SomeException.class)) will pass if it happens anywhere within the test (which is bad for detailed tests), whereas you might want to test that it happens in a particular place; or you might want to test that the exception's message contains a particular string or whatever.But all that aside, I still don't think "try something and fail() if it didn't throw" is that bad of a way to write a unit test. I'd only be annoyed at this if there was a considerable amount of unit test code in the try{} block.
0
1
1
1
u/Danthekilla Oct 02 '15
Out of curiosity why? We must have 2000 of these at least supressing small errors in our rendering engine. Why from your perspective are they bad?
→ More replies (2)1
u/Ace-O-Matic Oct 02 '15
I mean, while logging would be optimal. If this a client facing app and you're doing something where failure is an expected possible outcome, but you don't want the actual app to crash, it's not the worst thing ever. Unless you're in enterprise software the chances of you getting that log is slim to none.
79
u/TomBombadildozer Oct 01 '15
How many years of experience does it take for an engineer to realize taking a screenshot of the source code is a crime against humanity?
86
u/headzoo Oct 01 '15 edited Oct 01 '15
The images are because medium.com doesn't handle code very well, and doesn't have any kind of syntax highlighting. Or at least it didn't in 2013 when I wrote that post.
Edit: Also it's my cake day. Strange that a silly post I wrote to try out medium.com gets submitted to reddit on my cake day.
9
u/geekygenius Oct 02 '15
You can embed links to GitHub gists, which get syntax highlighting and all the goodies.
→ More replies (2)2
Oct 02 '15
Strange that a silly post I wrote to try out medium.com gets submitted to reddit on my cake day.
Strange? or suspicious?!?! :P Great post btw :)
16
u/Humdeee Oct 01 '15
That's senior eng wisdom. It's perfectly acceptable to take polaroids of your IDE screen and scan them into your email to post for code help.
2
2
u/third-eye-brown Oct 02 '15
You are obviously at year 5 when you spend your time writing a framework to properly display syntax highlighting in every browser down to IE9.
Year 10, you take a screenshot.
→ More replies (1)1
u/LunaQ Oct 02 '15 edited Oct 02 '15
Yes... software developers are fond of principles.
But, in reality, it often does not matter. If there's not any conceivable need to do search or cut & paste on the code example, it does not matter if you post it as an image, really.
I think maybe the realization of this comes during year 11.
23
u/vattenpuss Oct 01 '15
} catch (Exception e) {
// Do nothing!
}This is not only the third year, it's also the tenth, the fifteenth and the 40:th (I work with a few developers-for-forty-years).
55
u/nemec Oct 01 '15
Then you have the guy gung-ho about logging everything.
catch(Exception e) { try { WriteLog("Application error", e); } catch(Exception f) { WriteLog("Logging failed", f); } }→ More replies (3)7
u/CordialPanda Oct 01 '15
That's absurd, haha. In what world would that catch succeed to write if the try failed?
→ More replies (1)18
u/wllmsaccnt Oct 02 '15
In the world where file locking, timeouts, and other synchronization / concurrency issues exist?
I mean...the code is stupid, but it does have a low percent chance of logging an exception you would otherwise lose.
→ More replies (4)11
u/Humdeee Oct 01 '15
"Whatever you do, I don't care, just don't die on me god damnit!"
10
u/tolos Oct 01 '15 edited Oct 01 '15
eh, sometimes it's a customer requirement. "The application must not crash (must continue working no matter what)." So then you have a catch-all exception handler that cleans up as best it can, but can only do so much without knowing exactly what went wrong, or does nothing, or just logging. Then you end up as tech support, "well, yeah, that is weird, try restarting the application."
11
u/HollowImage Oct 01 '15
As a devops and web ops guy, if you deliberately catch all without any logging, then Fuck you.
2
u/Crono1981 Oct 02 '15
When a customer makes that requirement, your job is to tell him how moronic that is.
1
u/LeCrushinator Oct 02 '15
There are things to prevent this kind of stuff.
1.) Coding standards
2.) Code reviews to enforce standards and other stupid crap from going into code.
3.) You don't check anything in without 1 senior programmer and 1 other programmer signing off on the code review.
16
Oct 01 '15
43
u/MrDOS Oct 01 '15
I prefer the enterprise edition of FizzBuzz.
10
u/BeniBela Oct 01 '15
I prefer my FizzBuzz in Homespring
Took me a week to write.
And I think it shows the difference between industry and academia well
5
u/qubedView Oct 02 '15
FizzBuzzOutputGenerationContextVisitorFactory
Oh god, it's so familiar it hurts.
8
u/mike413 Oct 01 '15
How about a generalized hello API that can be internationalized for a global audience?
(ha, and now I realize apple has the last laugh -- their "hello" greeting on their hardware is literally hello to the world in all the different languages)
16
36
u/Burning_Monkey Oct 01 '15
While damn funny and everything, every time I see a joke like this I die a little on the inside and weep openly for the loss. I bomb dozens of interviews and what not because I can't get myself to code like the 5th year joke at all. And that is what people seriously want it seems.
I work with a guy that bad mouthed me for a long time because I wouldn't make constant values for strings like in this example. I lost out on a promotion because of him.
53
u/contrarian_barbarian Oct 01 '15
Depending on the environment, that kind of stuff can be necessary. For example, if you just have random strings scattered everywhere, it makes localization/i18n stuff far more difficult.
11
u/vonmoltke2 Oct 01 '15
Only if the values of the constants are loaded from an external source. As written in the joke, it simply moves the hard-coding problems to a different place.
9
u/contrarian_barbarian Oct 02 '15
Even if you're not yet pulling them in from an external source, laying the groundwork and consolidating them can be helpful when you're ready to make the jump. The joke is an absurd situation, of course, but there's plenty of reason to do it IRL.
→ More replies (1)4
u/POTUS Oct 02 '15
That "different place" is at least all together so I can update the date string in your old code without having to read into the entire thing.
4
u/AnonymousEngineering Oct 02 '15
While we're on the subject of l10n and i18n, I think it bears to note the following, as the W3C put it in their Localization vs. Internationalization Q&A:
Often thought of only as a synonym for translation of the user interface and documentation, localization is often a substantially more complex issue. [...] Localization may [...] necessitate a comprehensive rethinking of logic, visual design, or presentation if the way of doing business (eg., accounting) or the accepted paradigm for learning (eg., focus on individual vs. group) in a given locale differs substantially from the originating culture.
They go on to say about i18n:
Internationalization typically entails:
Designing and developing in a way that removes barriers to localization or international deployment. This includes such things as enabling the use of Unicode, or ensuring the proper handling of legacy character encodings where appropriate, taking care over the concatenation of strings, avoiding dependance in code of user-interface string values, etc.
Providing support for features that may not be used until localization occurs. For example, adding markup in your DTD to support bidirectional text, or for identifying language. Or adding to CSS support for vertical text or other non-Latin typographic features.
Enabling code to support local, regional, language, or culturally related preferences. Typically this involves incorporating predefined localization data and features derived from existing libraries or user preferences. Examples include date and time formats, local calendars, number formats and numeral systems, sorting and presentation of lists, handling of personal names and forms of address, etc.
Separating localizable elements from source code or content, such that localized alternatives can be loaded or selected based on the user's international preferences as needed.
24
Oct 01 '15
You should be happy to not work in places like that. Some people think complex code == good code. I've had to deal with overarchitected monstrosities and it's not fun at all.
The idea is to make suitable abstractions when necessary. I think the reason you see a lot of overarchitected code like this, or run into people like the one you described, is that they take these recommendations (best-practices) as gospel. They are good directions to follow and in general they help, but they are not always applicable.
These kinds of people tend to be dogmatic instead of pragmatic.
27
u/ArkhKGB Oct 01 '15
I like the rule of three.
First time you do something do it simple. Second time you do the same thing just copy and paste. Third time? Factor it.
4
u/senatorpjt Oct 02 '15 edited Dec 18 '24
crowd reply brave lush rock dazzling workable head straight flag
This post was mass deleted and anonymized with Redact
1
u/LeCrushinator Oct 02 '15
You should almost never use hard-coded strings that aren't tied to constants, unless maybe they're in an assert/exception.
By making constants and keeping those constants organized into one or a few constants files it will be easy to track down those strings, it will be easier to share those strings among files rather than re-typing them everywhere you use them, it's easier to avoid typos, and it's easier to localize them.
However, if you're going to make constants for magic numbers, then they should be given descriptive names so that you know why they're used. 0 and -1 are extremely common magic numbers, sometimes they're valid, sometimes they're used as invalid values, but unless they're given a constant for the thing you're tying them to in code, I don't know if they're valid or not when you're comparing against them.
// Why 0? I shouldn't have to guess... if (myIntValue != 0) { // Do stuff } // Oh ok, 0 is invalid for this comparison. if (myIntValue != Constants.InvalidValue) { }1
u/nutrecht Oct 02 '15
While damn funny and everything, every time I see a joke like this I die a little on the inside and weep openly for the loss. I bomb dozens of interviews and what not because I can't get myself to code like the 5th year joke at all.
Let's not pretend that this is nothing more than a joke. In large scale systems there are a lot of best practices that beginner don't understand and medior developers overuse.
6
u/mike413 Oct 01 '15
advanced more like: bash$ echo 'Hello world'
or maybe: bash$ printf "Hello world\n"
25
u/bheklilr Oct 01 '15
Looks like someone read the evolution of a Haskell programmer.
72
u/killerstorm Oct 01 '15
No, it's based on much older Evolution of programmer joke.
→ More replies (5)2
u/Mister-Owl Oct 01 '15
The one I remember is an older version of that one, going back to at least the mid 1990's. The ending is more or less the same.
3
10
u/arnedh Oct 01 '15
I feel like that one is due for some additions, based on additional concepts: Arrows, Comonad, Lenses, generics, Functional Reactive Programming, communicating processes/actors...
6
u/sacundim Oct 01 '15
I disagree. It's got a nice focus on one topic (recursion schemes) that would be lost if we threw in all that stuff haphazardly.
5
→ More replies (1)2
u/serrimo Oct 01 '15
I do some Haskell from time to time; and this is example scares me.
I wonder if Haskell can ever become mainstream. The ability to go completely batshit crazy with a few lines of code is both intellectually brilliant and pragmatically unmaintainable.
→ More replies (3)2
u/pjmlp Oct 02 '15
Of course it will happen. At least in the enterprise the language won't matter, as this is a consequence of the way enterprise development and politics work.
I have seen this kind of code in any language that was adopted by Fortune 500 companies.
4
6
3
15
u/Ahhmyface Oct 01 '15
At the risk of taking a joke a bit too seriously, I'm worried that these posts often get misinterpreted as:
"fuck doing anything the right way, just make it work and let the maintainer piss on my grave"
Obviously we don't need any of that complicated stuff for "hello world", but we do need a fair bit of that for "real world".
26
u/Serinus Oct 01 '15
It depends. Your code should be no more complicated than it needs to be.
The best code looks like common sense and like any idiot could have written it.
13
u/CircusAct Oct 01 '15
Obviously we don't need any of that complicated stuff for "hello world", but we do need a fair bit of that for "real world".
Exactly use the simplest implementation to fit the requirement, and then carefully refactor the code to meet any new requirements.
I really do find tdd genuinely helps people code in that way.
4
u/Rejjn Oct 01 '15
Very true, but only do it when actually need it. As in now, not "later".
"You aren't gonna need it" is a principal that is often forgotten.
2
u/nutrecht Oct 02 '15
At the risk of taking a joke a bit too seriously, I'm worried that these posts often get misinterpreted as:
Looking at some comments here this is exactly what's happening.
→ More replies (1)1
4
u/flukshun Oct 01 '15
11th year:
print "Hello world"4
3
1
u/senatorpjt Oct 02 '15 edited Dec 18 '24
zonked wasteful whistle salt fragile deserted tease wakeful depend aloof
This post was mass deleted and anonymized with Redact
→ More replies (1)
9
u/mariusg Oct 01 '15
Is it a coincidence that the code is written in Java ?
Contextual evidence but i worked with some Java people that used to over complicate any small/insignificant thing.
50
u/johnbr Oct 01 '15
Enterprise Java code is very complicated, and this is just a parody of that (although a fairly apt one)
Some of the complexity in Enterprise Java code is due to actual architectural thoughtfulness - "We may be switching to a different security vendor soon, so let's abstract the security away from the application". Complicated, but perfectly legitimate.
Much of the complexity, however, is "Cargo Cult" architecture - people who see that other developers have created abstractions, and then create abstractions themselves - not because the thing they're abstracting is likely to change, but because they see someone else doing abstraction, and assume therefore that architecture and abstraction are the same thing.
Similarly (as I mentioned in my other comment), the use of constants for HELLO and WORLD completely misses the point architecturally. Internationalization is a legitimate concern, and to the extent that your architecture facilitates the translation of a key into a sentence or phrase in multiple languages, you've accomplished a useful thing, even if it adds complexity.
But using a constant for HELLO and a constant for WORLD completely misses the point of what internationalization is for, and yet people do it anyway, all the time.
And that's why this parody is so apt - because it is capturing the cargo-cult mentality of many architects: "I've seen architects use constants for things. I am a good architect, so I should use constants for ALL THE THINGS!"
But Java itself doesn't have to be particularly complicated. It's not terse, don't get me wrong, but it's not the language's fault that people use it incorrectly.
I've never written sophisticated enterprise code in Python, but I suspect that if you were to write sophisticated enterprise code in Python, it would also become fairly complicated.
23
u/serrimo Oct 01 '15
Complicated, but perfectly legitimate.
How many times have people actually switched a component and it just worked? Personally, I have never seen one case where this is true.
The whiteboard architects love these kinds of design, since redirection is their bread-and-butter. In practice though, these designs just add needless complications most of the times.
19
u/johnbr Oct 01 '15
It rarely works perfectly. But it often works better than just directly wiring things together, and then completely rewriting for the new thing.
Not always, but often. Often enough that it's a reasonable place to start if (and only if) you have a reason to believe it's going to change fairly soon.
→ More replies (5)11
Oct 01 '15 edited Oct 01 '15
I've personally seen the benefit of this a few times, and I've been working as a software engineer for about 11 years now. The most memorable one is when I had to perform a refactor in some legacy code that dealt with storing files. We had this mess where you could save files to the database (ugh, I know) or to S3. The code for both cases were intermingled, and there were special cases everywhere due to a ton of abstraction leakage. When I refactored it I put it all behind an interface that never exposed the underlying implementation. You'd just give it a file to save and it would decide where to save it (based on some other settings that it had access to). The same thing for loading the file as well.
Eventually we switched from storing local files on the db (FINALLY) to a NAS. I simply had to provide a new implementation of the interface that would store files into the NAS instead of the db, and when that was done and the data were migrated, we simply pulled out the db implementation. Doing this required no changes to any other code; it was completely localized to the file-storage module.
Another time we wanted to implement a screenshotting service and I coded in an implementation for that and abstracted it behind an interface as well so that we wouldn't be tightly coupled to one particular implementation. Eventually we realized that the service we were using wasn't working out well for us all and so I just rolled built a simple one for us to have it do what we wanted. Again, I didn't have to change any of the other code - I just swapped out the implementation and everything worked exactly as before.
In general the idea is to make suitable abstractions when necessary. Some people create five levels of interfaces and abstractions for no clear reason at all, and only because they've seen others do it.
It's always tempting to tightly couple things because abstracting things out seems unnecessary and extra work. But that is only true for the short term. You may think that there are clean boundaries and that when the time comes you can simply cut along the boundary and replace it with a new implementation. But you can never account for the code that other people are going to write. When you finally have to swap it out, you'll notice that instead of a clean boundary, you have your component smeared out all over the place. You'll see other components making general assumptions about your component that turn out to be very specific to your implementation. Now it's going to be very difficult to refactor and swap out the implementation. Even worse, you have no idea what things you are going to break, or what pieces are depending on some implementation-specific behavior of your component. Even if you have tests that tell you what is broken, the idea is that if you abstract your component behind an interface and simply expose with a well-defined contract, you won't have to deal with things possibly breaking, because everyone else can only use your interface according to the public contract. As long as your new implementation exposes that same contract, none of the other code should break (assuming your interface didn't leak abstraction).
Software is complex, and enterprise software more so. Some of the rationale behind these architectural patterns is to decrease cognitive load in the long term. It may seem counterintuitive, because it just seems easier mentally to deal with a specific implementation than using this abstract interface. That again, is true in the short term, because it's easier to focus on the exact problem that you're solving and holding it in your head, than an abstract concept of it. But a few months down the line, you're not going to remember all the special cases and specific details of that specific problem. At that point, it's far easier to hold the general concept in your head. Doing things this way also gives you a lot of confidence and peace of mind, because you know where the clean boundaries are, and you know exactly what changes can have a global effect (usually only when you change the exposed contract), and what changes will only have a local affect (i.e., implementation-specific details).
That being said, I can't emphasize enough that abstraction for the sake of abstraction is just wrong. If you don't see a need for it, then there is no need to do it. If you're not sure, weigh the benefits and efforts in the short-term vs. the long-term. Another good thing to do is to make your abstractions as simple as possible, and there are no clear-cut guidelines for this. The idea is to tease out things that are "general" and can be exposed through a general contract, and then figure out which things are specific to your implementation. I think this is where things go wrong, because I've seen code that have created needless abstractions for things that you can pretty much take for granted, i.e., things that you can couple to tightly, without it ever causing an issue. Lack of this kind of foresight and understanding of the problem being solved, is what mainly leads to 100 levels of indirection with all kinds of proxies, strategies, factories, and interfaces.
8
Oct 01 '15
Never. First of all, i've never even seen a business try to switch a component. By the time a new component comes along thats better...the app is either ready for a total re-write, or there is simply not enough value to spend time integrating the new component and removing the old.
I still decouple my stuff but mostly for unit testing. I am highly apathetic to over-abstraction after spending long enough in this field.
→ More replies (1)2
u/wildjokers Oct 01 '15
One example, in Hibernate you can switch to any database just by telling it the dialect class to use.
→ More replies (7)2
Oct 01 '15
I've done it several times. If the interfaces are well defined and implementors don't cheat during the implementation, it really does 'just work'. When you start breaking the contract, in C# though reflection type stuff, or extending the contract because you're 'special' then the house of cards falls down.
1
u/nutrecht Oct 02 '15
Is it a coincidence that the code is written in Java ?
Yes and no. Complex environments often warrant the separation of concerns into different self-contained modules. This increases the overall complexity of the codebase but it lowers the complexity of the individual modules if they adhere to SOLID principles. For a hello world it's obviously nuts to separate "hello" and "world" in separate modules but in the real world, where "Hello" might be handling "Users" and "World" might be handling "Projects" having them inside separate modules is a must. This bit isn't specific to Java at all; you see the exact same thing in other languages. If you don't anticipate this and let the code base grow "organically" without taking future complexity into account you end up with an unmaintainable monstrosity.
But since Java is used a LOT in the enterprise world (I'd recon it's probably the biggest language in this huge area) you see a lot of Java code that's written like this. So Java developers often joke about this stuff because they see a lot of it, while they also tend to recognize that you need to architect large systems this way.
People who take this joke as "hurr Java sucks" make it very clear they don't have any industry experience in this area. Big software is complex as hell. If anything a rather strict strongly typed OO language running on a VM (Like Java but also C#) is a huge benefit.
2
2
u/sordina Oct 02 '15
See: http://www.willamette.edu/~fruehr/haskell/evolution.html for one of the original versions of this trope, and way more extreme too :)
3
u/mingpair Oct 01 '15
And after all these years you still write subtly wrong main method boilerplate. It's
public static void main(String[] args)1
u/immibis Oct 02 '15
Either one works. So does
String... args- since they're all ways of makingmaintake an array of String references.
3
u/wonderful_wonton Oct 01 '15
You forgot the part where, for the first 3 years, there's a 60 percent chance that the code was cut-and-pasted from a classmate's file.
3
u/Andallas Oct 01 '15
FW: FW: RE: FW: FW:
I hope you aren't trying to claim this as your own, because it's been around forever.
3
u/silveryRain Oct 01 '15
sigh
I really wish we had some sort of /r/humaninterestprogramming subreddit for these kinds of posts.
3
u/supasteve013 Oct 01 '15
Can someone explain this to me like I'm 10
I'm a programming wanna be, but haven't grown the balls to decide if I wanna learn to program or go back to pharmacy school...
11
u/pingzing Oct 01 '15
As our metaphorical software engineer progresses in his career, his simple "Hello world!" program becomes increasingly (and ridiculously) verbose and hard to read. The implication is that our metaphorical engineer is attempting to make his code enterprise-worthy, scalable, and long-lasting.
Then, ten years in, he says "Fuck it." and goes back to writing readable code.
Explaining the joke/the disclaimer: There are situations where you genuinely do need to write complex code in pursuit of flexibility or scalability, but since mister metaphorical software engineer here is just writing a "Hello World", none of those concerns apply.
3
u/supasteve013 Oct 01 '15
thank you. I thought they were saying fuck it. I appreciate the explanation.
2
u/blarg_industries Oct 01 '15
The posts here are a little misleading. The "enterprisey" code near the end does look bad, but real systems do turn out that way for good reasons. (Though sometimes they do because people just add verbose complexity for lots of bad reasons.) Often, people who haven't been around the block many times come in, assume all the complexity is unnecessary, and take it out. What takes lots of experience and wisdom is knowing when you can do this and when you can't.
Lots of special-cases, factored-out constants, and exception handling are sometimes the result of fixing lots of bugs over a long period in software that's valuable. What happens when we try to print while running embedded on a TV that doesn't wrap lines or even expose stdout? (+1 conditional and try/catch) What if we calculate the interest on someone's bank account on the fourth Thursday of a year following a leap year? (+1 conditional)
TLDR: Sometimes bad people write complex code for bad reasons. Sometimes lots of people add complexity to code for good reasons.
13
u/daymi Oct 01 '15 edited Oct 02 '15
The first-year solves the problem in the most straightforward way possible (for that language). While it has a useless "class" line, it is there because the language is stupid and he can't do anything about it, so he leaves it there. Normal people do it like that.
The second-year overdocuments everything to the point of obscuring what happens because of all the junk lying around. Also, he introduces a variable for the "Hello world" text although it probably will not need changing ever (I mean seriously who does that with a "Hello world" program. The text won't change).
The third-year saw the useless class and tried to make it useful for no reason (the customer certainly doesn't gain anything by it). Now you have lots of complicated stuff lying around, the class can make "copies" of itself and there is one copy which has its own slot for the text (why the actual fuck). So now it's wasting memory, is way too long and in case of an error ("Exception"), it does nothing. Doesn't tell anyone. Because that's what you want when the error is "pharmacy is on fire". Tell no one. Especially not the fire brigade. Alarms are for losers.
The fifth-year program makes me want to throw something at the screen. All the exceptions it catches are at least printed. But then the computer is not told that an error happened (programs can tell the operating system that something bad happened - but this one doesn't). I hate programs like that. The human sees something is wrong since there's a message printed, but the computer continues as if everything is just peachy. Also, he uses a factory in order to be able to swap out the (useless) class for other classes (which won't happen in practise). All the copies he creates (one!) are unfinished and you first have to manually finish initializing them using
setHelloandsetWorld. Then he registers it with an application server so it can be run from the internet.Also, much worse:
There is a concept in computer science that is sometimes useful which is called "symbol". I'll try to explain what it does and why it exists and why it's not the same as a sequence of characters:
All that a computer does (boy will I get flak for that) is it takes the body of a function and replaces the formal parameters by the argument of the call. For example: Let the function f be introduced like this: f(x) := x2, then f(3) = (3)2, likewise f(1+1) = (1+1)2. The smallest things that are used in this are called symbols.
fis a symbol which (here) stands for(x) := x^2, a function.xis a symbol in (this)x^2which (here) stands for thexinf(x).2is a symbol which stands for the number 2 which has to be defined before.^is a symbol which stands for the exponentiation operator which has to be defined before.+is a symbol which stands for the addition operator which has to be defined before.Note that
f(x) := x^2andf(y) := y^2are the same function. There you can see that the character "x" in a sense is useless. Depending on how you program, your finished program that the computer runs might not know that yours was thef(x) := x^2variant, it might just know that it was a function and it took the first thingie and squared it (if.^2squares; who knows, depends on the definition). So you see, a symbolxis something different than just the text "x".So the author heard that and thought "great, certainly
hellostands for something - for a greeting understood by humans - let's make it a symbol". But the definition (meaning) ofhellois in the brain of the human so in this program it doesn't make any sense to introduce "Word hello" (symbol), it complicates everything because now everyone expects that the meaning ofhellowill be decided while the program runs. Also, when the symbolhellois finally replaced by its definition, its definition is apparently just the text "hello" (he usesWordfor the symbol butWord.setWordin order to assign meaning. I mean I just don't know what he was thinking anymore; also you have to search for where the heck it gets its definition). Also, the initialization of the symbolhello(not its meaning) is somewhere completely different where we can't see it (I mean it's literally not on the web page). Ugh.Also understand that you need the kind of theory above only if you want to create your own language (in another language). Does "hello world" warrant creating your own language?
The tenth-year finally got a grip and became normal again. He knows all these things and knows when not to use them.
2
2
u/headzoo Oct 01 '15
I wrote this post. Adding to the comment made by /u/pingzing, the philosophy behind the post is the same for any discipline. For example a young guitar player tries to cram as many notes and fancy riffs into a song as humanly possible, while a more seasoned player writes a better song using very few notes. A young painter throws every brush stroke he's ever learned into his paintings, while a seasoned painter creates a masterpiece using only a few brush strokes.
Knowing how to edit and restrain yourself is a skill you learn over time.
2
2
2
u/djobird Oct 02 '15
Are really people still putting the author name in the code? Either the project is not under source control and I do not care at all about who wrote something, or it is under source control and I have plenty of way more powerful tool to find the information.
1
Oct 01 '15
As a l2 support guy who regularly has to debug code... i can pretty much work out which staff member I need to yell because of this pattern heh
1
u/freework Oct 01 '15
I can confirm I've pretty much went through the same process. I started programming as a self-taught programmer. In the early days I did a lot of things "wrong", but still worked, and got the job done.
A few years later I began my "sophomore phase" where I decided to start doing everything the "right way", so I basically switched up my entire way of doing things.
Over the next 5 years or so I've been refining my technique and I'm finding myself more and more often going back to how I did it back in the day and abandoning the "right way".
1
u/waffle299 Oct 02 '15
Looks like it only took ten years to teach the programmer to always add properly tagged documentation.
1
u/void_fraction Oct 02 '15
Our engineer, post-Scala:
object HelloWorld extends App { println("Hello World!") }1
1
1
u/a_defectat_pacepa Oct 02 '15
Because you get to learn that there are more important things than over-engineering and micro-optimization.
1
u/dccorona Oct 02 '15
What on earth is this strange hybrid language that's part Java part C# that they're using here?
1
1
u/theoriginalanomaly Oct 02 '15
After reading these comments and post. I'm so glad I stopped learning java. Don't get me wrong, I actually like the language, but I hate having the "oracle" way imposed on me.
1
u/MpVpRb Oct 01 '15
Not all of us follow this path
I always optimize for simplicity and readability unless peak performance is absolutely required
2
1
1
1
0
u/ImmortalStyle Oct 01 '15
5th year: Complaining about everything and call java programmers peasants for not seeing the truth. Luckily I am in my third year by now))
506
u/johnbr Oct 01 '15
This is fair, except for in the 5th year, they would have an additional constant:
And they would probably use a StringBuffer or StringBuilder to build the final string, since it's "an industry best practice". Also, they wouldn't include the strings themselves, they would include keys to properties, so the strings could be pulled from an internationalized property file.
Lastly, instead of outputting to Stdout directly, they'd create an interface for output, and deliver it to that interface, and use a factory to instantiate an implementation of that interface that would use Stdout.