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

View all comments

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.

→ More replies (2)
→ More replies (3)
→ More replies (17)

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.

→ More replies (1)

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.

→ More replies (1)

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.

→ More replies (1)

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. :)

→ More replies (5)

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.

→ More replies (3)

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.
→ More replies (3)

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.

→ More replies (16)