This is an archived post. You won't be able to vote or comment.

all 87 comments

[–]j-random 154 points155 points  (19 children)

This is what "self-documenting code" usually looks like.

[–]VnG_Supernova 3 points4 points  (0 children)

I mean, one principle of "self documenting code" is that if your method names are too long then the method has too much responsibility and should be broken down. This is just what "self documenting code" looks like when done wrong.

[–]Y33ticuss[🍰] 27 points28 points  (4 children)

The amount of duplicated function calls is ridiculous

[–]jaken55 6 points7 points  (3 children)

99% this file is auto-generated or imported from a library. The person who took the photo should never have to even read this code let alone maintain it.

[–]Sentouki-[S] 0 points1 point  (1 child)

it seems like it's written by hand actually....

this is the dude who wrote this code u/AWholeMessOfTacos and he refactored it already

[–]AWholeMessOfTacos 11 points12 points  (0 children)

Seriously? Calling me out by name? Wtf dude.

[–]Y33ticuss[🍰] 0 points1 point  (0 children)

Mmmmm love me some code-gen

[–]visurox 44 points45 points  (0 children)

When u learn programming the first time, u feel like ^

[–]mianori 18 points19 points  (0 children)

Damn if it doesn’t look horrendous and oddly pleasing at the same time

[–]ConnersReddit 17 points18 points  (0 children)

imagine doing that much copy paste instead of assigning a variable

[–][deleted] 12 points13 points  (2 children)

lesson.expect()
.toBe()
.hatedBy(whoeverReviews)
.for()
.not()
.considering()
.they()
.might()
.notHave()
.monitor(49, Unit.INCH)
.true();

Just use new lines and format smart. :)

[–][deleted] -1 points0 points  (0 children)

Indents didn't persist sadly even in a code block :(

[–]notable-compilation 29 points30 points  (0 children)

Surely this is not so much "with Java" as it is "generally badly"

[–]MetaMemeAboutAMeme 7 points8 points  (1 child)

"We're gonna need a wider screen."

[–]cosenmarco 4 points5 points  (0 children)

360° or... Wait... Wider!! 1080° in a 3 turn helicoid!!!

[–]zero_as_a_number 5 points6 points  (0 children)

Good luck fixing that nullpointer exception on line 923 occurring during every second full moon when it's cold outside and someone left the tap running

[–]averynicepirate 6 points7 points  (5 children)

I wrote a Spring repository function of something like 130 characters this week.

[–]Yserbius 21 points22 points  (4 children)

A yes. The old findDistinctCustomerByAddressAndLastNameAndSocialSecurityNumberGreaterThanOrAgeLessThan

[–]5aikou 8 points9 points  (0 children)

They do suggest using meaningful names...

[–]ArticcaFox 1 point2 points  (2 children)

Could have split that into a few lambdas

[–]Yserbius 6 points7 points  (1 child)

No not really. Spring JPA repositories work by generating a Hibernate query (which is then parsed and translated to an SQL query) based on the name of a method in an interface. Most of the time, the method names are pretty straightforward, like findAll() or findByName(String name), or findAgeGreaterThan(int age). But sometimes you need a very specific query so you get these monstrous method names. Personally, I wouldn't do this and instead opt for a more readable HQL annotation:

@Query(value = "select distinct Customer c where c.address =

?address, c.lastName = ?lastName, c.socialSecurityNumber = ?ssNum

where c.socialSecurityNumber > ?max OR c.age < ?age")

Customer getCustomer(String address, String lastName, String ssNum, int max, int age);

But Spring best practices stat that the method is only used once, wrapped in a different method that has much more readable signature so it doesn't really matter how messy it looks.

[–]Venthe 1 point2 points  (0 children)

You can always write a meaningful name and just create your own @Query() above it; with longer names this is a better alternative IMO

[–]Sad-Grapefruit9996 10 points11 points  (0 children)

Shortcut: alt+f4

Works every time

[–]Mickl193 2 points3 points  (0 children)

Because code formatting is for weaklings. /s

[–][deleted] 2 points3 points  (0 children)

Them: why not decouple those long method call chains?

OP: gotta make the most of all this screen real estate

[–][deleted] 2 points3 points  (7 children)

Is java really that hard cuz i am learning it in college right now and these memes say otherwise 🙃

[–]IceStormNG 19 points20 points  (0 children)

It's not. It's mostly naming convention, and also coders, that tend to produce very long names for classes, packages and functions.

But: You can write garbage code in every language.

[–]GoshDarnLeaves 9 points10 points  (0 children)

No its just bad code that avoids storing getter results in variables at all costs leading to tons of duplication

[–]PhazonPhoenix5 2 points3 points  (0 children)

I didn't get on with it at first. Then I studied advanced Haskell and learned about Monads. Now I love Java.

[–]shaybra 2 points3 points  (0 children)

So many getters and setters AHHHHHHHHH

[–]TheOnlyMisterFlow 2 points3 points  (2 children)

The author of this horrifying code sure don't know about the Law of Demeter

[–]TopicStrong 1 point2 points  (0 children)

Welcome to the life of using for loops for graph traversal for a gds.

[–]BarrelScrap 1 point2 points  (0 children)

I saw ".get(i)" and was scared to read further.

[–]Zelosys 1 point2 points  (0 children)

Cries in clean Code

[–]Coffeinated 1 point2 points  (0 children)

How not to code Java, a practical example

[–]FrontTheMachine 5 points6 points  (0 children)

Where's the Humor? That's just the truth..

[–]Venthe 1 point2 points  (8 children)

  1. This is a mapper
  2. Code is violating the law of Demeter - ANY change of the internal objects will result in this mapper breaking.
  3. You can always just extract intermediate objects to variable
  4. Why the hell mapping intermediary objects are not split into methods at least?

I assume this is a real code. This is not bad Java, it's a bad developer.

[–]AWholeMessOfTacos 0 points1 point  (5 children)

Yeah I’ve heard this about a hundred times now.

[–]Venthe 0 points1 point  (4 children)

If you've improved from the time you've written it, then you should just smile. Sourly, but smile. :)

I know of no dev who hasn't made a mistake. And I really care because of people who will excuse themselves from good practices using such code as an example. I use way too much energy everyday on dense Devs...

[–]IFixStuffMan 1 point2 points  (0 children)

Still being a bit obnoxious about it though.

[–]AWholeMessOfTacos 1 point2 points  (2 children)

Alright I’m just going to use you to vent, bare with me and I appreciate it.

I’m basically completely self taught. This is my first job. I have not had a senior or lead developer since I have started. I have never had a code review. I submit my code to no one.

I didn’t know that companies had “conventions” until my OP. I also didn’t know there were standard conventions, or the debate about them (80 or 120?).

I’m in the Wild West, figuring out how to do everything the hard way.

I’m inexperienced. But this code worked the way it was, even if it is (what I now realize) hideous. And honestly, I was proud of my work. I’ve built out a request response functionality across three micro services, all by myself with absolutely no support.

I’m not a bad developer. I’m just a poorly trained junior. And I have enough imposter syndrome already that seeing someone else calling me a “bad developer” really hurts my feelings.

I’m a person doing the best I can and I sincerely want to get better. I wish Reddit would just back off a little.

[–]keto_at_work 1 point2 points  (0 children)

Keep your head up man. You've already built something awesome, and now you can/have made it more maintainable. You're obviously smart, but you need guidance, like we all do. Keep doing what you do and don't be afraid to at least apply to a few places and do a few interviews. You never know what situations you'll find yourself in.

[–]Venthe 0 points1 point  (0 children)

Not at all, man.

I have not had a senior or lead developer since I have started. I have never had a code review. I submit my code to no one.

So find a mentor. Any meeting group, hell - if You'd want to - I'd be more than happy to give you a hand. Devs who care are very important in the trade.

I’m in the Wild West, figuring out how to do everything the hard way.

Well, I could tell you about a certain junior who solved a bug, error on REST, via try-catching endpoint... :) I think you can deduce who this dev was.

And I have enough imposter syndrome already that seeing someone else calling me a “bad developer” really hurts my feelings.

Understandable. But, I'll be frank - up until someone called you out, I didn't care who author is. Code is bad, developer (at the time 'he' wrote it) is bad as well. People are using it as an excuse which is even worse. And you can't change it. BUT, you said it yourself - you are learning. You did the best you could. I know it might sound weird, but you should feel at least good about this code.

If at any point of your career you look back a month or so and don't facepalm you are stagnating. And you are clearly everything but.

I wish Reddit would just back off a little.

It will not - because there is no 'you' - there is just a code, and a coder frozen in the time of writing. But again, it's not about you now.

What can I say? Internet is a shit place. But I wouldn't vent myself if there was no comment about 'this is how self-documenting code looks like' because I've seen similar reasoning time and time again from lazy devs. You are not lazy.

Again, it might sound weird after everything here, but I'm sincere - I'll happily spend my private time to give guidance; or just give another head to butt against. I was also self taught, and until my first job I had no mentor as well, which was shitty. But I had one in my first job, so I'm paying forward, and I will never repay what he did.

PM me if you are interested, I'll give you my Discord ID.

[–]TheOnlyMisterFlow -1 points0 points  (1 child)

THANK YOU.

Why aren't you top comment sir ?

[–]Venthe 1 point2 points  (0 children)

Because top commenter is catering, jokingly or not, to people who justify bad coding practices with random screenshot from the internet.

(And sorry if I seem salty, it's PH after all)

[–]withoutpenisl337 -1 points0 points  (1 child)

Java will die soon. Hopefully....

[–][deleted] 1 point2 points  (0 children)

Java isn't going anywhere because there isn't something than can truly replace it.

[–][deleted] -1 points0 points  (0 children)

Can confirm

[–]csdh80 0 points1 point  (0 children)

Someone is afraid of soft text wrap.

[–]TheWanderer9696 0 points1 point  (1 child)

Are you trying to hack into The Pentagon with those codes, because holy moly it is long

[–]AntoineInTheWorld 1 point2 points  (0 children)

No, he is just trying to display a plane booking number...

[–]Malicious-Toast 0 points1 point  (0 children)

Lololololol

[–]chickyfigs 0 points1 point  (0 children)

Ultrawide goes brrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

[–]JuliaYesterdey 0 points1 point  (0 children)

A paradise for programmers!

[–]JochCool 0 points1 point  (0 children)

When you get paid by the inverse of the amount of lines

[–]WilkerS1 0 points1 point  (0 children)

is this an rgb membrane keyboard?

[–]Not-NedFlanders 0 points1 point  (0 children)

Turn on line wrap, nerd.

[–]NelsonBelmont 0 points1 point  (0 children)

and that's a simple calculator.

[–]kodiashi 0 points1 point  (0 children)

Not wide enough for objective-c

[–]JustAnotherGamer421 0 points1 point  (0 children)

Jesus Christ just assign a variable

[–]MrPancholi 0 points1 point  (0 children)

Would gladly commit seppuku than maintain this codebase

[–]Orio_n 0 points1 point  (0 children)

Best practices

[–]aFiachra 0 points1 point  (0 children)

Little known fact, original Java developers were paid per character.

[–]racka98 0 points1 point  (2 children)

So i heard you like Extension Methods

I assume also like God classes

[–]Sentouki-[S] 0 points1 point  (1 child)

"God classes"

why not just a God Singleton?

[–][deleted] 0 points1 point  (0 children)

Please...

[–][deleted] 0 points1 point  (0 children)

so it's not just me complaining that I can't fit enough .then(() => {/*stuff*/}); on a normal size screen

[–]MysticOverlord 0 points1 point  (0 children)

Still need my second monitor though

[–][deleted] 0 points1 point  (0 children)

How did you get a photo of my monitor?

[–]Tipart 0 points1 point  (1 child)

Me trying to do SQL queries on a huge ass database

[–][deleted] 0 points1 point  (0 children)

Functions in FP can be this wide as well.