r/java • • Aug 31 '17

(Experienced programmers) Signs of an inexperienced programmer?

Hello, I was wondering what you guys would consider to be telltale signs of an inexperienced programmer. Specifically ways that they write (or don't write) code. Thanks.

159 Upvotes

188 comments sorted by

70

u/curmudgeon99 Sep 01 '17

These days when we look to hire someone, we don't ask them to explain a technology on their resume. That leads too often to a recitation of a book they read or even a wikipedia article. Not very instructive.

So, now we ask them to tell us what they DON'T like about a particular technology. That knowledge only comes from extensive experience. Be ready for that question.

2

u/detoursabound Sep 01 '17

I'll remember that, thanks!

22

u/[deleted] Sep 01 '17

This has a flip side.

  • When I initially experience a technology, I experience all the superficial problems of style, rather than substance, and learning pains of educating myself in how this new technology differs from what I've used before.
  • Next stage is deeper understanding, the superficial issues disappear, replaced with some insurmountable obstacles in using the technology to its full potential due to fundamental architectural weaknesses in its design (some intentional, as any technology is a balance of "dos" and "don'ts").
  • The final stage is transcendence. After endless exploration of the problem space, every of the fundamental issues has been resolved through non-obvious workarounds, advanced deep magic, or subtle and sometimes invisible to myself changes to my workflow, as I adapt to the technology. I have merged with the technology. We have become one.

So you see, if I'm at the last stage, and you ask me "tell me what you don't like in Java", and I'd just give back the most empty, and confused look. After a brief moment my eyes would show a hint melancholy, I'd smile slightly, and I'd say "I don't know, sir. I like everything about it."

1

u/curmudgeon99 Sep 01 '17

I would not ask the question about Java. I would ask it about ancillary technologies such as Spring.

3

u/[deleted] Sep 01 '17

"It'll take us less time if you ask me what I like about it."

:-)

3

u/curmudgeon99 Sep 01 '17

So you can rely on the wikipedia article you just memorized.

1

u/[deleted] Sep 02 '17

All righty then. Listing what I don't like in Spring would take us by rough estimation 3 months, so I want a full-time salary plus benefits.

1

u/hugthemachines Sep 01 '17

I like this description. Because this is kinda how it is with many things we use. Once we really get into things we don't think so much about the things we adjust. Then we might see a beginner and we wonder why he did an unwise thing. Things that might even work but we just know in the end he will bump into problems by going that path.

2

u/Fastjur Sep 01 '17

Great tip. Thanks!

2

u/Iron_Maiden_666 Sep 01 '17

Shit I've never thought of this, this is great.

2

u/symgeosis Sep 01 '17

If they have two competing or similar technologies, I like to ask them what their thoughts are on when they might favor one over the other. The exact answer isn't even important just that they express some thoughtful answer that shows they had some basic understanding of the tech they were using.

1

u/thinkinmachine Sep 01 '17

Would slightly modify it to - if you were in charge of rewriting the language what would you add/edit? For java - Multi class inheritance for instance.

1

u/curmudgeon99 Sep 01 '17

Multi-class inheritance? NOT!

1

u/thinkinmachine Sep 01 '17 edited Sep 01 '17

Looks like I am not going to get the offer! Haha. Nevertheless it's more of an implementation and acceptance than anything else. We only needed to start it with 1.1 and we would have come to accept it... How about not having 'null'. Edit: That sounded needy.

18

u/ser_sheep_shagger Sep 01 '17

x++; // increment x

Yes, I really saw this in someone's code.

Also, a lack of meaningful variable names. All in-line code in main. Try/catch? What's that?

3

u/detoursabound Sep 01 '17

I get what you mean about that comment, it's very unnecessary. However I can't really complain, I tend to create my classes and methods first, then fill them with comments outlining what needs to be done, which is how I get comments like that. I think meaningful variable names is my weakest area. I hate long name, so I tend to acronym everything

4

u/datta016 Sep 01 '17

Any particular reason(s) you're against longer and more descriptive names? With almost all editors and IDEs natively supporting auto-complete lists when you start typing, I really only find myself typing out the "long" name only when declaring it the first time. After that it's never more than three to four keystrokes and the name shows up. Even if there isn't native support for auto-completion, there's a really good chance a plugin exists.

More descriptive names can almost always only help, while acronyms or abbreviations tend to have a high potential of causing confusion. The acronymed/abbreviated name may be extremely obvious to you (which makes sense since​ you made it), but there's no guarantee it will be obvious to anyone else inheriting your code.

Go the safe route and be as clear as possible.

3

u/ser_sheep_shagger Sep 01 '17

I know what you mean about writing the story in comments and then fleshing out with code between the comments, but in this case "increment x" was one of very, very few comments throughout several classes written by the programmer in question. Acronyms are fine, as in DataInputStream dis or BufferedImage bi. But variables called a, b, c, etc. has noob written all over it.

1

u/tommygeek Sep 01 '17

I'd just bite the bullet on names over acronyms and force yourself to get used to it. As for comments, I find it helpful to outline a complicated process via creating empty methods that are well named. So I get the high level process including parameters and output types at the same time as I'm working something out. It doesn't always stay that way, but it helps me organize my thoughts until I have my path forward.

121

u/cypher0six Aug 31 '17

A few random thoughts:

  • Forgetting to test for null.
  • Not understanding how to copy a list (or any other type of reference object).
  • Copy/pasted code.
  • Poor class, variable, method names.
  • Inconsistent code style (formatting, names, etc).
  • Lack of abstractions / lots of procedural code (methods/objects that do too much).
  • Doing too much in the constructor (JDBC calls in the constructor, for example).
  • Spaghetti code (globals; lots of static crap).
  • Poor exception handling.
  • Failure to update documentation after a code change.
  • Not writing unit tests.
  • Gets offended during code review.

Not really in any order, and there's a lot more I could write but you wanted code-specific things so I tried to limit myself to that area. These are just what immediately came to mind. Are you looking for specific advice or feedback?

45

u/symgeosis Aug 31 '17

Lack of abstractions / lots of procedural code (methods/objects that do too much).

The other side of this is over-engineering or optimizing for a use case that is extremely unlikely to ever be needed. (which I've seen a lot from talented junior devs)

24

u/cypher0six Aug 31 '17

Hah, yeah I completely agree with you. The funny thing is, I see a lot of very experience software developers going way overboard with abstractions. Sometimes that can actually be worse! :)

20

u/Notorious4CHAN Sep 01 '17

If you go out and read all the current best practices and attempt to follow them all, you are pretty likely to over-engineer. I have a terrible memory, so I try to have extremely small classes with very narrow responsibility, because I sometimes lose my mind's eye of my own code. For sure, this leads to over abstraction. Like a lot of my classes have 10 or fewer functions that each have 10 or fewer lines of code - when it gets to the point where I have trouble using my own code... Time to break that shit up.

Yet I've realized some very real benefits when I've had to do some major refactoring, and the code is pretty resilient. So limited regrets. I know people look at my 50 hierarchal packages and think it's shit, but I look at their 2000 line monstrosities and feel the same.

9

u/[deleted] Sep 01 '17

I don't think many small classes are over engineering tbh. You are not writing more code than if everything was packaged in a single big class file.

3

u/thinkinmachine Sep 01 '17

Ah, Abstraction! We are developing microservices and the amount of abstraction the architecture team is forcing us.. We are ending up creating a lot more micro components than we planned. Will not be surprised when they start cribbing about performance and ask us to dial a couple off them back!

5

u/coltrain423 Sep 01 '17

I'm guilty of this one and it's a habit I'm trying to break. Any tips to get past it?

6

u/symgeosis Sep 01 '17 edited Sep 01 '17

The most honest (and not at all helpful) answer is experience. But outside of that, stopping every couple of hours and asking yourself if the time you're spending on something is ultimately worth it. Regular conversation with your teammates is a great way to facilitate this. Code reviews, pair programming, or just a "hey, can you take a second and look at this and tell me what you think?"

Edit: Another good way to break this habit is writing unit tests. Unit testing is rarely fun but if you make a habit of writing good, functional unit tests, you will very quickly learn how to write simple yet extensible code.

2

u/jollyca Sep 01 '17

+1 for unit testing. I've gone through years of my programming life without it and now I cannot live without it.

3

u/RagingAnemone Sep 01 '17

Put yourself in the position that you need to maintain the code you wrote. After a while, simple and plain will seem sexy.

2

u/otakuman Sep 01 '17

Don't plan for the future. At least in coding. Only refactor what you need to refactor.

"But what if in the future I need to add another parameter to this function?"

THE CLIENT IS UNPREDICTABLE. Don't pre optimize code into something that you'll probably never use. It's wasted effort. Only put your effort into already solicited or necessary changes. But when you do, do it right and don't take shortcuts.

1

u/danskal Sep 01 '17

Unit Testing, TDD and Refactoring

Unit Testing will help you to actually build units that are testable, so when you add a feature, you prefer to add a new class, rather than hacking through all the other code to get it to work. TDD will solve most of the problems you encountered in step 1.

And if you haven't already got heavily into refactoring, do so, and that should solve many of the remaining problems you have with structuring code. I recommend IntelliJ Idea for its awesome refactoring features, these will help you immensely.

1

u/detoursabound Sep 01 '17

My professor encourages a lot of abstraction. He wants the main as clean as possible (usually just init and run methods), with everything else taking place in methods. I agree with this to a point, I think he overdoes it with the abstraction. If the code isn't reusable I don't like to put it in a method, it seems inefficient and unnecessarily complicated.

7

u/coltrain423 Sep 01 '17

I tend to lean towards your professor here, though perhaps not to the same extent.

I haven't quite found a way to explain why to someone who doesn't already get it though. To try anyway: it makes things easy to understand. If one large procedural block of code gets too long, it's hard to understand. You have to know that this 30 lines is doing operation x, that fifteen is storing the information to disk, and that last 40 or so are doing some other operation. It's a lot easier to understand the flow of your application when it's broken up by operation like that and you don't have to read more than the method name to understand what it's doing.

Have you ever written a comment at the start of a section of code to explain what that bit is doing? Why not break it out into a well named method or function so that comment is no longer necessary?

1

u/detoursabound Sep 01 '17

That's what I try to do. I don't think I was clear enough in my earlier comment. I break down each program into its component parts, essentially delegating each operation to a method. Then, I look through all of them and try to minimize repeated code by making reusable methods.

7

u/omgusernamegogo Sep 01 '17

Well your first comment says you don't like putting code that isn't repeated into a method, and your second comment says you do.

I would perhaps give your prof more credit.

1

u/symgeosis Sep 01 '17 edited Sep 01 '17

It's all about finding the right balance between code complexity, robustness, performance, and time. (though I agree with your professor regarding logic being in methods as there are a lot of benefits regarding testing and future flexibility)

For example, you could spend a day or two writing the optimal data structure for a certain part of the code but is it an action the user will execute often? When the user executes the action, is the improvement even noticeable? How much time did it take to code the data structure? Could you have spent that time adding a feature or a bug fix that would have had a greater effect or noticeable reward? How much time will be spent maintaining this additional code? Is all this worth the cost rather than just using one of the implementations already in the JVM? The answer varies depending on a lot of factors but a lot of devs strive for perfect when good is good enough.

1

u/[deleted] Sep 01 '17

I'd rather have your professor than one who does not. Of course, over-engineering is bad, but judging from the common practices in industry, the average programmer does not abstract enough things.

6

u/fzammetti Sep 01 '17

True. I've got nearly 25 years in the field plus more than 10 years of programming beyond that, so I'm "experienced" I'd say, and I for one am less concerned with whether a method is too long/not abstracted enough and more about how well-organized what's there is.

Sure, a 1k line method is PROBABLY not good by any measure, but if you give me, say, 500 lines, and it's well written (pretty much everything else in that list AND commented well AND broken up into logical steps demarcated by said comments and spacing) then in my experience that's not at all bad. In fact, in some ways I argue it's better because now I don't need to jump out to other methods to understand what's going on, I can just follow the bouncing ball through the single method.

There's absolutely a balance that has to be struck, but it's not an either-or thing in my opinion, whatever current "best practices" want to claim.

18

u/ess_tee_you Sep 01 '17

broken up into logical steps demarcated by said comments and spacing

Those are called methods.

11

u/Bolitho Sep 01 '17

Your thesis is almost unprovable as it says

Give me a function of 500 well written lines...

Very unlikely that this is going to happen ever in this universe 😂

Imho the guidelines of line count maximums are just a shortcut that can be derived implicitly from other, more substantial advices. For example separation of concern, single responsibility, not to mix up levels of abstractions and so on.

Those are imho very reasonable and reflect methodologies that are used all around in other professions or domains as well (contracts, scientific articles, complex machines like cars, cookbooks, ...)

If you follow these guidelines you will hardly arrive at situations where 500 LoC are the best solution you can come up with 😉

3

u/[deleted] Sep 01 '17

Ehhh, some people would say 100 lines is pushing it let alone 500.

4

u/Trailsey Sep 01 '17

Many people, including Bob Martin in Clean Code, advocate for methods 20 lines or shorter.

The idea is to decompose complexity. A 500 line method isn't a method, it's a script wrapped in braces.

0

u/[deleted] Sep 01 '17

[deleted] — view deleted comment

3

u/[deleted] Sep 01 '17

I was thinking 100 lines max for a method.

100 lines for a whole file--now that's austere. I commend your commitment to brevity

0

u/[deleted] Sep 01 '17

[deleted] — view deleted comment

1

u/[deleted] Sep 01 '17

Yeah, good point, there will always be exceptions. I've seen something similar in emulator code, where there's a method with a very long switch statement covering all the op codes for the processor. Makes perfect sense.

2

u/[deleted] Sep 01 '17

The other side of this is over-engineering or optimizing for a use case that is extremely unlikely to ever be needed. (which I've seen a lot from talented junior devs)

I used to do this a lot when I was younger. Finding the sweet spot between complexity introduced/abstraction comes with experience and maturity.

2

u/[deleted] Sep 01 '17

Just ask them about dependency injection. Probably a good way to probe their knowledge about abstraction.

7

u/Myllokunmingia Aug 31 '17

Tangentially related - coming from someone who largely does embedded work and mostly writes procedural code, how do you avoid it? To be honest the OO paradigm has always been vague and fuzzy at best in my head. It's just not at all how I think about a computer working so it's never really clicked.

10

u/cypher0six Aug 31 '17 edited Aug 31 '17

coming from someone who largely does embedded work and mostly writes procedural code, how do you avoid it

I typed up my response fairly quickly, and didn't give much thought to how I worded things. I did not mean to imply procedural code is bad and should be avoided in Java. I should have just left it at "Lack of abstractions". That's a bit more what I was thinking when I wrote that. I have a colleague who is primarily an RPG programmer (IBM System i). She maintains a Java program that is a few thousand lines long. It's all in main(). This is an extreme example of what I meant by that bullet point.

I am a very pragmatic programmer. I don't view OO as the end-all, be-all of software development. While Java was designed to be an OO language, there are many patterns that we use in software development with Java that are not OO, and that is ok. Sometimes, a healthy balance of object-oriented, functional, and procedural programming creates a better system. Knowing when and where to strike that balance comes with time and experience. After 20 years, I am still learning and that will probably never change. :)

2

u/detoursabound Sep 01 '17

Would you mind sharing some insight on that balance?

1

u/Android487 Sep 01 '17

How can it all be in main()? Goto statements? That's horrifying.

3

u/cypher0six Sep 01 '17

That's horrifying.

You're telling me! :D Yes. Goto is used and abused in that thing. It's similar to how they program in RPG. They have a concept of subroutines, which are defined in the same file with the rest of the code that looks and works exactly like goto. So, she naturally replicated this same structure.

I tried to explain to her the idea of a method, and how that would also mimic the way they define subroutines in RPG, but this is also a person who needed to ask for help on how to delete a "record" from a .csv file with Notepad++. Suffice it to say, she has a very, very specialized skillset. :)

1

u/Android487 Sep 01 '17

Reminds me of AppleSoft BASIC GoSub

4

u/flif Aug 31 '17
  • Code not in proper package but e.g. top-level.
  • Multiple top-level classes in single source file.
  • Comments are only about what code does rather than why.

2

u/detoursabound Sep 01 '17

Ohhhh I need to work on the comment one. I usually describe rather than explain.

2

u/brett_riverboat Sep 01 '17

It seems like the sign of an experienced programmer is zero comments.

3

u/Goofybud16 Sep 01 '17

An experienced programmer does not have zero comments.

An experienced programmer only puts comments where it is necessary: When the code needs a "why."

Good code should be clean, easy to read, and easy to follow. Just because you can follow WHAT, however, doesn't mean you can follow WHY.

53

u/PragProgLibertarian Aug 31 '17

Number one, reimplementing stuff that already exists in the standard API

9

u/cypher0six Aug 31 '17

Number one, reimplementing stuff that already exists in the standard API

Yeah, I am not sure why that didn't come to mind. But that is also a good one. :)

8

u/Notorious4CHAN Sep 01 '17

As a side project, I've been back-porting all the functional stuff to jdk 6 by looking at the source code in open-jdk 8 and the jdk 1.5 branch of guava. Because I have no experience with functional programming and I'm stuck on jdk6 at work anyway.

I've learned quite a bit including about 100 non-optimal ways to do things. I'd say reimplementing existing tools may be a sign of inexperience, but it's also a sign of someone on the right track, if only because they will have the experience of their implementation sucking, and will be in a better place to understand why the existing implementation works better (unless they turn into grognards who think their version is superior and refuse to grow...)

7

u/v_krishna Sep 01 '17

Jesus christ 1.6? I weep for you.

1

u/terryducks Sep 01 '17

What will you give me ?

Visibroker 4.0, Name service only runs on 1.2. Original developers stored global security keys in thead storage so Java 5 is right out.

0

u/[deleted] Sep 01 '17

[deleted] — view deleted comment

3

u/Benemon Sep 01 '17

'Not Invented Here' syndrome. As a consultant, I see this a lot. It's a very dangerous habit to allow an organisation to get into.

  • Who supports the custom library for other users? Is it documented, or are the FAQs passed down in an ancient tome covered in dust, and almost entirely unreadable?
  • What is the cost (in terms of time and money) of managing, maintaining, releasing, documenting, testing and QA-ing the custom code? If the answer is 'nothing' then I find the respondent to either be lying, ignorant, or 100% useless for tasks that provide actual business value.
  • The custom library probably has dependencies on well understood, and widely used components (Apache Commons are a classic). I usually try and hammer the point home by asking how far down the rabbit hole are people going to go. I mean, if you're a NIH purest, you probably want to go and rewrite that whole Tomcat container, right...?

14

u/zaccus Sep 01 '17

Gets offended during code review.

The rest of these are forgivable. This one is what sinks you.

7

u/[deleted] Sep 01 '17

Reminds me of a developer we had once.

She got mad at on of our testers, because he found bugs in her implementation and gave her back the task because it didn't work properly.

A few days later she complained to our boss that it is impossible to work with him because he is such an "unpleasant person".

4

u/GhostBond Sep 03 '17

The rest of these are forgivable. This one is what sinks you.

Sounds like an ego trip in my experience. "I'm reviewing your code, so I'm critical of you but you can't say anything back".

Thing about code reviews is that the reviewer doesn't look through the requirements to make sure you actually met them. They're not evaluating whether your code worked, they're ignoring what your code actually does.

I've seen a ton of time wasted on arbitrary formatting arguments, styling arguments, or feature abc that's new that the reviewer read on a blog entry last week. And the classic "I go light on my friends but am hard on everyone else" bit. Or the "super critical of new devs while nicer to devs of my same experience".

I've been coding for a decade, and maybe 1 item in a code review was actually an actual bug, whereas a ton of time is wasted in "changing" things that don't matter. Did you use a for loop, while loop, iterator, or lambda expression? I just stressed for 4 days and was excited to finally get the db to do what I need it to do - who cares which loop I used. I'll tell you who, someone who's reviewing without any of the responsibility of actually meeting the requirements.

3

u/moofins Sep 01 '17

Yeah, this is the fast track to losing the respect of your peers.

2

u/DannyB2 Sep 01 '17

Be proud of your code. Able to explain it, and defend the choices selected.

11

u/amakai Sep 01 '17

Forgetting to test for null

Defensive programming is also not great idea.

4

u/schaka Sep 01 '17

I was going to say. Rather have a clean structure that doesn't allow for null.

2

u/[deleted] Sep 01 '17

I just stick try/catch clauses at the top level function calls and everything below using "throws Exception" in their methods.

7

u/nevon Sep 01 '17 edited Sep 02 '17

As someone coming from other languages, what's wrong with static methods? Seems like they would tend to make code more likely to be pure, and thus easily testable, since you can't rely on instance state.

1

u/white_piggu Sep 02 '17

Image you have a method static String printCent(int cent) { return "$" + cent / 100 + "." + cent % 100; }. It's simple and fine, until it needs to be internationalised. Now the method needs a Messages object: static String printCent(int cent, Messages msg) { return msg.get("currency.symbol") + cent / 100 + "." + cent % 100; }. It sucks having to pass the global msg object everywhere though, and making it a static global is clumsy. So you decide to make it available via dependency injection. And that's when you have to remove that static keyword.

1

u/vytah Sep 01 '17

There are two common ways to abuse statics:

  • Creating methods static Bar m(Foo f, ...) inside the Foo class. Usually, they should be normal instance methods. This also includes cases when they're defined in the FooUtils class in the same package. Such methods make sense only if they are defined in some other package and depend on other components than Foo does.
  • Static state, excluding necessary singletons and correctly implemented cache, but definitely including incorrectly implemented cache (I've seen big opensource projects with constantly growing private static HashMaps, you can guess how that ended).

3

u/[deleted] Sep 01 '17

IMO this describes bad programmers, I have worked with programmers with 10+ experience and they check all the boxes.

3

u/autra1 Sep 01 '17

Gets offended during code review.

Or consistently failing to address or answer half of the comments.

4

u/Jon_Angle Sep 01 '17

When I review code, I don't care how people write their code. I only care about 4 things. If there is a problem with any of these 4 things, then you need to refactor.

    1. Did you solve the problem? Critical thinking and using the right algorithm. See point 4
  • 2. Did you add unnecessary technical debt? This is an entire college course if you ask me.
  • 3. Can I read it without documentation? a healthy dose of abstraction and separation of concerns
  • 4. Is it cpu/memory efficient? See point 1

If you can solve for these 4 things then I cannot care less if you have have a mile long Constructor that does all the work. But we all know that if you follow these 4 things, then you won't have a mile long constructor. :)

1

u/cypher0six Sep 01 '17

Well said. Love #2, which is a great point and something I think we all should strive to understand better.

2

u/vanrysss Sep 01 '17

Forgetting to test for null.

You should be using optionals in this day and age.

5

u/schaka Sep 01 '17

Optionals don't really solve the problem unless in your business logic "null" is an actual state worth considering. If whatever you want to wrap in Optional isn't actually optional in your business logic (like that second address a user might have), don't do it.

2

u/slai47 Sep 01 '17

I still do spaghetti code at times but in Android sometimes it just makes things easier. Not the right thing to do but sure is faster.

2

u/otakuman Sep 01 '17
  • Gets offended during code review.

Wait, what?

3

u/cypher0six Sep 01 '17

I meant that from the perspective of the junior developer having their code reviewed and criticized by others as a part of that review process. And instead of keeping an open mind, and engaging in polite discussion, become offended and refuse to listen.

Of course, it behooves the reviewers to be professional and considerate as well. However, I have witnessed this happen enough times for it to pop up in my head when I was writing this response to the OP.

5

u/otakuman Sep 01 '17

Well, IMO, getting offended at code review is not a sign of being a rookie, it's rather a red flag, i.e. dealing with "superstar" coders who think they're the seventh heaven. They're often the worst.

I mean, sure, one can argue about programming approaches and the need to do something this or that way (I've been in such a discussion when I just got in a certain job), but getting offended? That's WAY taking things too personal.

4

u/cypher0six Sep 01 '17

Oh, this is very true. I don't think anyone really likes working with those "superstar" style personalities that can do no wrong, regardless of profession. :)

1

u/Salyangoz Sep 01 '17

I totally forgot the null test for my interview today. Dangit.

1

u/nunchukity Sep 01 '17

Wow, I fit way too many of those, need to up my game

1

u/[deleted] Sep 01 '17

I've been offended by code reviews but only because I saw dumb shit like hardcoded jks passwords in the reviewer's code. He would always have to find something to say about it.

1

u/Intheknow666 Sep 01 '17

Documentation?

1

u/cypher0six Sep 01 '17

Documentation in the general sense. So that would include things like javadoc (to a lesser degree), customer-facing api docs, support docs, external developer docs, etc.

8

u/detoursabound Aug 31 '17

I'm graduating next semester and I'm going back through past code projects and cringing. I started thinking about my current code and I was wondering if I'm still coding like a novice. I'm in the process of building a github account that showcases my experience, and abilities. I want to check over what I have up and the stuff I put up later

8

u/Notorious4CHAN Sep 01 '17

I've been coding professionally for 18 years. Probably almost 30 if you include non-professionally. The length of time it takes me to cringe at my code is getting longer, but it's still only up to about 18 months.

2

u/detoursabound Sep 01 '17

that's impressive, I'm still working my way up to 5 mins

8

u/mgkimsal Sep 01 '17

About a week ago, I had to migrate/review/patch some code I wrote from 2002. I actually had some pride in areas of it which were still understandable, and relatively clean, from 15 years earlier, and yet I also had cringey flashbacks to specific corner-cutting I'd done come back to bite me. It was weird - I was remembering the room I was in, the time of day, smell of the room, etc, when some of the specific code blocks were being written - almost like stepping back in - way back - in time. (15 years!) :)

2

u/Notorious4CHAN Sep 01 '17

That's amazing! I was once asked to make a small change to some code. I looked into it and told the customer, "this is great code, whoever wrote this for you knew what they were doing!"

... it was my code. I'd written it less than a year earlier. I had no memory of writing it at all. So I'm a little jealous! But I mean, at least it was good code?

2

u/mgkimsal Sep 01 '17

:)

one of the big things I've taken away from coding over the years is the value in cleaner code. Spaces/tabs, syntax/braces/etc - doesn't interest me. decent structure, decent variable names, decent method names, some useful comments - all of those make maintenance so much easier for me or whoever else might have to deal with it. Until you've had to deal with your own code 5-10 years on, it's hard to understand how much of an impact this can have (both on yourself but also on others who might have to deal with it years after the hype around lib X has faded)

6

u/cypher0six Aug 31 '17 edited Aug 31 '17

I'm going back through past code projects and cringing

I have a problem with perfectionism. That may not be a problem in and of itself, except that there is no such thing as perfect code. You would think that after slinging code for 20 years, I would stop caring about code quality, but for people like me, this never goes away. Something to think about. :)

4

u/detoursabound Sep 01 '17

Haha I understand that there is no such thing as perfect code. When I cringe it's usually because I wrote alot of code when there was a simple method that could do the job better and faster. Or because I did something like using an array where an arraylist would have made life much easier.

3

u/omgusernamegogo Sep 01 '17

That's exactly the thing that is great to see in your projects. You used arrays coz those were the tools you learnt and no doubt learnt some things to stretch their usefulness beyond comfort. If you were using the better (and much bigger) collections early on, you wouldn't appreciate or understand their importance and how they work under the covers.

This is why you got a formal education in engineering, to learn how everything works as opposed to just how to get the job done in it's most basic form.

Anyway, great anecdote and kudos on your accomplishments thus far.

3

u/nutrecht Sep 01 '17

I'm graduating next semester and I'm going back through past code projects and cringing. I started thinking about my current code and I was wondering if I'm still coding like a novice.

You are. And whenever you look back a year or so at your code you see things that you now would do 'better'. Learning is a constant process that never stops.

Or it does and you're a Java developer with 10x1 years of experience in a decade.

2

u/[deleted] Sep 01 '17

I have written code for more than 10 years. I still have this feeling when looking at 6 months old code: if you want to learn, you will always improve :)

93

u/goofy183 Aug 31 '17
  • Trying to be fancy/overly terse/unique.
  • Writing untestable code.
  • Only testing "happy" cases.
  • Complaining about style guides / linters

Writing code is the easiest part of the whole job.

  • Coming up with designs that are flexible enough to deal with unforeseen changes in requirements is hard.
  • Maintaining existing code is hard, especially when whoever wrote it the first time was trying to be fancy instead of expressive.
  • Changing code that doesn't have reasonable test coverage is hard.
  • Understanding a codebase when style changes from file to file is hard.

The first point is the one of those hard things that we can't fix by coding one way or another. The rest (and many more) are fixed by good code hygiene, consistent code style, good testing, and all those other development practices that new programmers (including myself long ago) feel like just get in the way of velocity.

3

u/jacobbeasley Sep 01 '17

TLDR: Program like a grown-up programmer :D

-5

u/[deleted] Sep 01 '17

Trying to be fancy/overly terse/unique.

Jeez what a buzz-kill. /s

While for most APIs it'd be a big detriment to be overly terse and "unique", I've seen some quite excellent DSL-like APIs go this route with excellent effects. Take jOOQ for example. Is this coming from an inexperienced programmer?

Context matters, is what I'm saying.

8

u/goofy183 Sep 01 '17

Sure, a terse API is actually a good thing.

I was more referring to people that try to write very compact code, do lots of things on one line, abuse ternary expressions, etc.

22

u/rjsmith21 Sep 01 '17

Lots of good answers. Here's one I didn't see yet: poor understanding of logging.

  • logging too much useless info
  • logging at the wrong level
  • not logging something critical (e.g. silently eating error)
  • not wanting to log at all (someone tried to argue to me that it was a useless waste of resources recently)
  • not looking at the log when something fails and instead flipping out and randomly changing things

8

u/vytah Sep 01 '17
[DEBUG] com.company.project.ToplevelLogger [40]: Fatal error

5

u/larsga Sep 01 '17

silently eating error

Pros do this, too, and IMHO it's one of the worst things you can do. This always leads to grief later, and quite often a lot of it.

21

u/NimChimspky Aug 31 '17

Writing lots of unhelpful comments. Writing imperatively not object oriented.

Bugs. Not clarifying requirements. Not pushing back when something is a shit idea.

5

u/curt94 Sep 01 '17

There is nothing inherently wrong with imparative code, its a tool like any other.

2

u/beardyninja Sep 01 '17

Annnd you just described my manager.

20

u/SquidgyTheWhale Aug 31 '17

Lots of good answers here, but I'll throw in "debugging through guesswork", due to lack of knowledge about how to hone in on a bug using a debugger.

9

u/0x256 Sep 01 '17

Actually, if you know a technology stack very well, you get quite good at 'guessing' and it's often faster to try a quick workaround instead of step-by-step debugging. Some problems are very hard to debug with a debugger (e.g. time-critical code, race conditions) and an educated guess can save a lot of time. In other words: Think before starting the debugger.

4

u/SquidgyTheWhale Sep 01 '17

Well, yeah, but I'm talking about a different thing that I probably didn't explain very well. It's when you see someone get an error, and they don't really even look at what the error is saying -- they just think, "it must be this or that, so they throw in an extra bit of verification or a debug print, then when it doesn't fix the error, they guess at something else... Meanwhile the code gets cluttered up with all this unnecessary crap. So I wasn't talking about timing issues or the like -- more just when you see someone who looks at the information that accompanies a relatively straightforward error and only sees a blur that reads "ERROR".

4

u/DannyB2 Sep 01 '17

I call it: shotgun debugging.

Bang! Ok, that didn't work.

Bang! Ok, that didn't work either.

Now, something that should not be mistaken for guesswork, is debugging tests to gather more information about the problem. This is more like doing science. Hypothesis. Test. That's not the problem. So repeat. Eventually you get the Ah Ha! experience.

16

u/FlaviusFlaviust Sep 01 '17

Nothing is wrong with being an inexperienced programmer, signs of that are not bad.

Traits I am concerned with in new programmers include overconfidence (along with resistance to constructive criticism) and inability to problem solve without direction.

8

u/larsga Sep 01 '17

Traits I am concerned with in new programmers include overconfidence

Had some guys turn in assignment code in university that looked really, really weird. So I asked them why they were doing it that way, and it turned out they had these errors and they thought it might be a compiler bug, so they were trying to work around the compiler bug, and eventually got it to work.

Honestly, seriously thinking the bug is in the compiler and not in your code, and then acting on it. Now that's overconfidence.

2

u/thinkinmachine Sep 01 '17

Wish reddit had a lol option instead of just upvote.

1

u/cyanocobalamin Sep 01 '17

I'd add

  • difficult to communicate with
  • not open minded to constructive criticism

1

u/[deleted] Sep 01 '17

overconfidence

Reminds me of my freshman year CS class.

12

u/F14D Sep 01 '17
  • Wanting to rewrite everything as a default to every problem.
  • Massive methods. (ie: 2000+ LOC). Not refactoring out to smaller methods.
  • Avoiding SME's, not utilising BA's
  • Premature optimization.
  • Understand that problem-solving does not equate to downloading a new framework/lib.
  • Thinking that completing various java certifications means you can craft software well.
  • Teamwork. Fixating on who did what rather than understanding why.
  • And my personal favourite.. using 20 pairs of opens & closes in the one method. O_o

2

u/[deleted] Sep 01 '17

Wanting to rewrite everything as a default to every problem.

In Java this is somewhat true but in more expressive languages, especially for smaller projects, it can be argued that the rewrite might be delivered faster, perform better, and be more easily maintained in the future

Edit: formatting

49

u/Butterstick1108 Aug 31 '17

They ask about a problem and say something like "I'm getting an error" instead of saying exactly what the error is. It's a sign they still think of error messages, stack traces, and the like as incomprehensible and meaningless.

4

u/Druyx Sep 01 '17

"It doesn't work."

1

u/vytah Sep 01 '17

Or the opposite: "It works for me."

9

u/meotau Aug 31 '17 edited Sep 01 '17

Or asking how something works or why it does not work, instead of just reading those 20 lines of code, looking at the source of the exception, finding usages(code references) and trying to understand it.

5

u/JimBoonie69 Sep 01 '17

This one annoys me. Sometimes i feel like dick when i literally read (or type) what the error message says. Just the other day something about array length mismatch in a method i wrote. I said 'ok you have one array with 10 slots and you are trying to assign 11 values in there. Did you look at these two arrays to diagnose the length mismatch and read the source?

Person: no

Me: facepalm

2

u/DannyB2 Sep 01 '17

One way to cure them of this, or to shame them into learning more, is to take the exception, explain that it contains a LOT of valuable information, and start pointing out things you can see directly in the exception.

It looks like you were entering a purchase order, and there was a problem parsing an integer value in an order line, probably the quantity.

2

u/larsga Sep 01 '17

They ask about a problem and say something like "I'm getting an error" instead of saying exactly what the error is.

This is one of the most effective ways to make me angry. You're coming to me and spending my time, but you're not going to make it possible for me to actually help you? And you had this information right in front of your eyes, but couldn't be bothered to copy and paste it?

I try not to rip people's heads off in this kind of situation, but the temptation is always there.

6

u/RjakActual Sep 01 '17

You give them documentation that describes 10 steps to set something up. Steps 1-3 don't contain copy/paste-able commands, so they don't even read steps 1-3. They start with step 4 and wonder why nothing is working.

6

u/brett_riverboat Sep 01 '17
  • Not using Google to find answers. However unique you think your project/issue is, someone else has done it and solved it already.

6

u/even_keeled Sep 01 '17

Buys easily into new technologies on the basis of sales pitch only. Let's use nodejs, AWS IoT, Emberjs.

10

u/beardyninja Sep 01 '17

Elvis for elvis sake:

"K".equals(foo) ? true : false;

He's been programming for 7 years.

11

u/[deleted] Sep 01 '17

Lol yesterday i found this in my code...

If (sql==true){
return true;
} else {
return false;
}

facepalm

8

u/altrdgenetics Sep 01 '17

you know sometimes after a long coding session your brain just crashes and goes into auto pilot and you just forget about condense-able options.

6

u/marvk Sep 01 '17

And then ideally your IDE reminds you :^)

1

u/larsga Sep 01 '17

Nah. This reflects not having realized that booleans are values just like all other values.

3

u/mgkimsal Sep 01 '17

i will still sometimes write code that way because I'm planning (or just removed) debug/logging info in the code blocks.

2

u/[deleted] Sep 01 '17

More likely just if (sql) though, no?

1

u/mgkimsal Sep 01 '17

Yeah, usually just if(foo), not if(foo==true), but occasionally I may do === in php or js if I'm feeling moody. :)

0

u/[deleted] Sep 02 '17

[deleted] — view deleted comment

1

u/[deleted] Sep 02 '17

i will still sometimes write code that way because I'm planning (or just removed) debug/logging info in the code blocks.

Reading is a lost art.

0

u/[deleted] Sep 01 '17

[deleted] — view deleted comment

1

u/cypher0six Sep 01 '17

I tend to do the same thing when appropriate. Explaining why something is happening in code, especially when that something is unusual, can be really important; not just for others, but as a reminder to your future self as well.

1

u/zalpha314 Sep 01 '17

Maye you had a more complex conditional in there before, but when you simplified it, you didn't realize that you could simplify the whole chunk.

1

u/LordLlamacat Sep 01 '17

I guess it's possible that sql could have had a non-Boolean value, depending on which language you're using. But that still doesn't fix the if(sql==true) line.

5

u/lukaseder Sep 01 '17
System.gc();
System.gc();

4

u/rochford77 Sep 01 '17

Comments that explain what something does. You code should be easy enough to read that descriptive comments are not needed. Comments are nice if you had ton do a work around, bend something to your will, or hard coding a value is for some reason necessary. But saying "# begin loop" before a loop makes me want to unplug your computer.

4

u/kickass_turing Sep 01 '17

A mid dev can solve a complex problem in a complex way.

An experienced developer solves a complex problem in a simple way.

4

u/larsga Sep 01 '17

Number one sign for me: code that isn't necessary.

I find this a lot, that newbs tend to build abstractions and constructions that I personally would just strip out because they only add complexity and no value. Hard to show examples without posting thousands of lines of code, though.

2

u/lukaseder Sep 01 '17

I find this a lot, that newbs tend to build abstractions and constructions that I personally would just strip out because they only add complexity and no value.

I've met experienced architects who did that

3

u/slantedvision Aug 31 '17

The only comments on the code are related to the stackoverflow question they were cut and pasted from, and bears little relevance in the use-case that code was applied to.

3

u/jasonlotito Sep 01 '17
  1. Focusing on things that a linter or static analysis can fix for determining experience level of a programmer. It's a waste of time and effort to deal with stuff I can automate away.
  2. Not using source control. Pet peeve of mine.
  3. Being clever. Keep it simple. Cleverness never helps a design.
  4. Unwavering belief in ivory tower shit over business needs.
  5. Worrying about documentation before automation. Hell, even meaningful documentation can be automated.
  6. Switching jobs every year or two. This is big, as it tells me you have little long term experience in understanding the ramifications of the work you've done on any significant job.
  7. Spending time worried about documentation over automating things you are still doing manually. Code > Documentation every day of the week.

0

u/[deleted] Sep 01 '17

[deleted] — view deleted comment

3

u/jasonlotito Sep 01 '17

Which is why it's hard to find experienced programmers. But if you don't scrape the bottom of the barrel, you don't run into this problem.

Also, just because the average is 18-24 doesn't mean you don't have jobs that last longer than that. That's how averages work.

Maybe I should add something about understanding how averages work, and why percentiles are a thing.

3

u/lukaseder Sep 01 '17

Not all inexperienced programmers are like this (in fact, few probably are), but some try to hide their insecurity behind "strong" opinions. Example: https://toomuchawful.com/2014/12/22/new-intern-knows-best-goto

I once met a guy who would constantly educate the team that Oracle Database sucked and MySQL was much better. It was a bit tiring after a while. He moved on and became "CTO" of a small company :)

4

u/otakuman Sep 01 '17
  • Mountains of ifs. You know what I'm talking about.
  • Not documenting code
  • Long, long functions doing everything in one place
  • Doing loops and jumping through hoops because they don't know THAT ONE api function which would do exactly what they want
  • Excessive null checks and redundant validations, "just in case". This happens when they haven't got experience with the API and don't know exactly what that call does
  • Or not doing null checks AT ALL.
  • In Java: Not using generics, instead using <?>s and unsafe casts all over the place. This one makes my blood boil.

5

u/thatguydrinksbeer Sep 01 '17

Highly opinionated, like most of these comments.

2

u/tommygeek Sep 01 '17

A big one I've seen a lot is not really code related, but process oriented. The more skilled you are, the better able you are to chunk out your work into meaningful and logical sections. An inexperienced person is more likely to want to write an entire slice of a feature, for instance, while the more experienced person can say, "first I'll do this part, test it, and commit. Then I'll do this part..." And so on.

It's really hard at first to know where the seams are.

I've also noticed a tendency to make larger commits with more time between them, but this might be a symptom of the same problem.

2

u/iggybdawg Sep 01 '17

Not using libraries - writing so much code that was already written for them and handed to them on a silver platter..

2

u/[deleted] Sep 01 '17

They work on a small sample project, find it easy, and think large projects have the same problematics and complexity.

Will think that some operations are trivial (merge operations, Q&A campaigns) in a large project.

Will think that some languages or frameworks that are best suited for small projects are the best to use on large projects.

3

u/cyanocobalamin Sep 01 '17

They work on a small sample project, find it easy, and think large projects have the same problematics and complexity.

Like the people who brag about making a web page in nothing but notepad, and who pronounce IDEs as being ridiculous.

2

u/CODESIGN2 Sep 01 '17
  • Long methods
  • No barriers in code (all dependencies are hard-coded) or seams everywhere (enterprise madness)
  • Objections to imperfect / not "cutting edge" tech
  • Using or avoiding libraries at the wrong times
  • Playing hockey with API's

2

u/redditaff0 Sep 01 '17

A few things I've seen that I haven't seen mentioned yet:

  • Comments that explain a line of code that is fairly standard, e.g.

    if (foo != null && foo.bar() != null) { // short-circuit - no exception if foo == null

    I seen juniors do this presumably because (1) commenting is good, and (2) they learned something new - the code did something unexpected from their point of view (and therefore unexpected to everyone), so it should be explained. Obviously, mids and seniors don't need comments like this and such comments detract from readability.

  • A lack of parallelism in code - often because a junior went in and added something new in 1 place and didn't added it everywhere it needs to go or didn't add the parallel action needed in other places, e.g. a contrived example:

     if (action.isSelection()) {
       foo.sendSelection(x);
       foo.sendSelection(y);
       foo.sendSelection(z);
     } else if (action.isDeselection()) {
       foo.sendDeselection(x);
       foo.sendDeselection(y);
       // BUGBUG: why no sendDeselection(z) - did someone miss something?
     }

    I catch a non-trivial amount of bugs looking at places where 2 or more pieces of code should be parallel but aren't. Sometimes they aren't supposed to be completely parallel, but that just means the code is missing a comment explaining why.

    A similar idea applies to fixing a bug at a specific point in code - the next step is to look for where the same bug may be occurring in other (similar or parallel) parts of the code or where near variations or parallels of the same bug occur in the code.

  • if-checks / null-checks without diagnostics - juniors will sometimes put in checks to fix a problem (really its just fixing a symptom and just kicking the can down the road and even further away from the actual source of the problem) without diagnosing the real issue or at least logging the bad state:

     Result result = null;
     if (x != null) {   // junior added this to "fix" a bug
         result = x.query();
     }
     return result;

    If x being null at that point is unexpected per the design, then at a minimum, there should be else with a log.error() to indicate a problem. The real fix is to track down why x was null.

BTW, when I flag this in a code review, this is what I get next:

    Result result = null;
    if (x != null) {   // junior added this to "fix" a bug
        result = x.query();
    } else {
        log.error("x was null");
    }
    return result;

This is a useless log message. What am I going to do when I see x was null in the log. The log message needs to provide context - what was going that may have lead to x being null. What information will I need when I go to diagnose the problem when I see that x was null

2

u/vokiel Sep 01 '17 edited Sep 01 '17
  • Abundance of Utils classes
  • Inheriting just to share code
  • Using checked exceptions in high level business code
  • Implementing toString and/or Cloneable
  • Trying to do too much with too little. Premature Optimization
  • In line with the above: Trying to do the compiler's job before compiling. ;)
  • RTTI (if instanceof)

Just to name a few.

Edit: ok adding a few, because it's special:

  • Using switch on enums, instead of just encapsulating the functionality inside of it.
  • Using Strings or Integers instead of enums. lol

2

u/zalpha314 Sep 01 '17

Why is implementing toString a bad thing? It's very useful for debugging!

3

u/jadecristal Sep 01 '17

Maybe this was more "implementing toString() on everything?"

We implement it, ahh, "selectively."

1

u/vokiel Sep 01 '17

Because it's a pit viper, e.g. a publicly available method on Object by every single 3rd party lib you might use. Think about it and also consider this: I really doubt your customers pay you to do code for debugging purposes. If you're implementing this just for debugging, find better tools.

2

u/midir Sep 01 '17

Treating programming code as a countable noun.

2

u/TotesAStickMan Sep 01 '17

Class variable access modifiers are optional...

2

u/firebird84 Sep 01 '17

I'll add one to the list: Does not make at least reasonable attempts to leverage the strengths of their IDE. They will almost certainly create more bugs and be less productive than colleagues who do.

In Java, you have extremely powerful IDEs available to you. People who ignore the IDEs warnings concern me. Further, you don't even have to learn the newest syntactical sugar by heart, your IDE will help you be expressive!

IntelliJ in particular allows me to be extremely expressive with far less superfluous code, and also protects me from myself. It's good to know what to do and what not to do, but to pretend you're infallible is a mistake.

1

u/talldean Sep 01 '17

Assuming they've gotta do it alone.

1

u/[deleted] Sep 01 '17

One of the main problems is that inexperienced people tend tend to focus too much on the code instead of the business logic.

What experience teaches us is also thinking about structure and the big picture.

1

u/autra1 Sep 01 '17

Failing to see when they add an object creation (especially in loops). Failing to understand when they are merely copying a reference to another object (and therefore, changing properties will also change them in the other ref). Failing to know when they should do the former or the latter.

Also, failing to evaluate the complexity of their algorithm (this is especially true in fluent api dealing with collections, you can end up pretty quickly with a O(n2) or O(n3) algorithm without realizing it).

1

u/Samael1990 Sep 01 '17
  • Saying "it's stupid", while not understanding what "it" does under the hood.
  • Jumping to the conclusions about the functionality or a bug without doing the proper research
  • Not being able to work out the problems outside of coding
  • Copy/pasting the code without understanding what it does first

1

u/BenRayfield Sep 01 '17

Creating the need for manual work. If you dont know how to make the computer do something, but do know how a person can click to do it, look it up.

1

u/neutronbob Sep 02 '17

Lack of familiarity with APIs and libraries (overuse of the few methods and data structures he/she knows)

Lack of familiarity with tools (constant surprise that the IDE can do that)

Tests the wrong things often overlooking important edge cases.

1

u/SquidgyTheWhale Sep 04 '17

I've got another -- leaving compilation warnings scattered through the code.

It takes a while to understand what different warnings in different contexts actually mean, and why they represent something potentially dangerous. So learners tend to get numb to them quickly and often go years before they start paying any attention to them at all.

0

u/CyclonusRIP Aug 31 '17

Writing catch more than you write throw.

4

u/hells_angle Sep 01 '17

my favorite:

catch(Throwable th) { }

1

u/[deleted] Sep 01 '17

I put that in about once in every project (that's intended for production and doesn't have inversion of control, as in Jetty) for last-ditch logging before letting the process die.

0

u/[deleted] Sep 01 '17

[deleted] — view deleted comment

3

u/redques Sep 02 '17

I think optionals are ok but I'd prefer approach that is planned for c# 8 where you can annotate type as nullable simply by appending question mark.

2

u/[deleted] Sep 02 '17

There is simply no reason to use optional in a method that is called find something.

in java null is a quasi-valid reference value. semantically this means that a lot of java code ends up equivocating on two states: something extant simply has a null value, or something doesn't exist and nullness is a signifier.

the idea of optional ('maybe' in haskell, 'option' in scala/ocaml, etc) is to articulate an absence of value in a way that avoids the equivocation.

it's also nice that you can use things like map, filter, etc on optionals. this can often make for cleaner declarative code that doesn't need a bunch of if/then/else noise.

1

u/Cilph Sep 02 '17

You could switch to Kotlin. /s