Top 5 Terrible Java Coding Techniques You Need to Be Using Right Now

preview_player
Показать описание
How to write horrifically awful Java code!

Any fool can write good Java code, but it takes an expert to create truly awful, unreadable, impossible-to-maintain Java code. That's what we'll be learning in this lesson!

What makes code bad? There are many ways you can create terrible Java code, and we'll go over a handful of techniques you can use to make other developers hate trying to read your code.

By the end of this video, you'll be able to create Java code so bad that no one will be able to decipher it for years to come.

Learn or improve your Java by watching it being coded live!

Hi, I'm John! I'm a Lead Java Software Engineer and I've been in the programming industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java learners.

Let me know what else you'd like to see!

Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.

📕 THE best book to learn Java, Effective Java by Joshua Bloch

📕 One of my favorite programming books, Clean Code by Robert Martin

🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial

🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)

📹Phone I use for recording:

🎙️Microphone I use (classy, I know):

Donate with PayPal (Thank you so much!)

☕Complete Java course:

Рекомендации по теме
Комментарии
Автор

I died when he said:
"Now you will always know in which line of code you have the problem..." (when you only have 1 line)

talk
Автор

You can get pretty down thinking about all the things you don't know. Sometimes it is good to be reminded of what you do know. So thanks this was oddly encouraging haha

JThompson_VI
Автор

Here's an advanced technique I like to call Re-try: Surround the contents of each method with a try / catch block, and in the catch block, re-call the method with the same parameters. This will enable the application to continuously run a method until it succeeds. Now you've got persistence both in the business logic AND the data layer! After all, if at first you !succeed...

Astroz
Автор

You know what Java really misses to be a great language? A goto statement. It's a shame that at some point they decided to get rid of such advanced feature.

DmitriiGlandarius
Автор

Another PRO tip, use as many different libraries as possible. Somebody put a lot of sweat and tears in them and they deserve that they're work is being used. Furthermore you can prove to the team and your boss how much libraries you know!

greg
Автор

lol, the int i global was hilarious. Someone I know spent a lot of time debugging a program when one of the i variables was being accessed outside the loop. Not me of course, I would never...

Miketar
Автор

"You're not here to _think_, your here to code."
I laughed for a solid minute.

austingarcia
Автор

As a new java programmer, some of these ideas seem really good to implement into my code! Thank you for the tips :)

OwenGalaxy
Автор

wow, what if someone tryes to read your code? its a giga security factor that someone might understand what's going on with those nicely named variables and methods, isnt it better to just call variables like... v1, v2, v3? same goes for methods -> m1, m2, m3.. you could try harder you know! its almost a readible code, who would want that? its not like you write your code once, refactor and then read it hundreds of times... a well written code does not need to be checked upon ever again anyways

Inkeri
Автор

People underestimate the power of "teaching" like this. If you do the complete opposite of the way it should be done, you can keep it better in mind how you really have to do it. Great work, John :D

rudigerheissich
Автор

If you're working at the enterprise level, remember that you gotta work fast and with minimal impact. Every time you're asked to implement a new feature that's similar to another existing feature, never spend the time to factor out commonality. Doing so is error-prone, and when it comes to testing, you now have to test the all the similar existing features as well as the new one, and who knows how long it takes to fix those? There's just too much work for very little gain.

Instead, you copy-paste the most similar feature, renaming it to whatever it is you need. Don't worry if you miss a few things in the comments. No one but you reads this code anyways, and really you should just be reading the code, because you're a professional. Then, you modify it as needed per your customer requirements. Not only does this avoid triggering a retest of existing features, but it scores you points with your customer, who will be very impressed with your turnaround time.

Now I know what some of you more experienced software engineers are thinking. Doesn't this vastly increase your technical debt? Trust me. Your customer doesn't care about that. They're paying top dollar for you to solve theirs and any that you incur ought to be included in the price, and you're gonna get paid that price, because you're working at the enterprise level. I mean, by the time the technical debt really starts causing problems, you'll probably be working somewhere else that pays more because you gotta keep up with inflation.

Zeero
Автор

There's a SERIOUS logical flaw in your code.
You're passing a single boolean to the if condition, which is nonsense as it could be either true or false. There is a common practice to help Java to understand booleans, like literally:
Hope I could help writing more robust code.

acradpictures
Автор

Do note that after you replace all of the newlines with spaces, you should replace all of the tabs with spaces too. That way, the file size becomes incredibly smaller and your monitor will thank you!

dryjoints
Автор

After years of studying at university with no success I gave up and got a job as an intern at a big corporation dealing with large chunks of Java source code. I had no idea how to code in Java but thanks to you I've learnt the very basics and I realized that the source code they used was incredibly flawed. I've now updated the entire code base to follow your tips and standards, and I have to say that everyone is super pleased with the increased file sizes, the massive reduction in lines of code, and the amount of keyboards broken by developers debugging problems on line 1, that last one really adds a lot of enthusiasm to the workspace atmosphere. Thank you for this.

Yours Sincerely,
A now-very-good Java programmer

avananana
Автор

"Do you have an int i variable for your for-loop? Yep, you guessed it! Global." gave me a good laugh

kayson
Автор

As a javascript developer, I honestly agree with the extra processing power that is saved from putting all the code in one line.

HuntingKingYT
Автор

ProTip: Name your variables, methods and such using really difficult to understand names. Like:

public class c____
{

int i = 0;
int i__ = 1;
int i___ = 2;
int i____ = 4;
}

That way your coworkers will ask you what they do instead of trying to figure it out for themselves.

TheSeanUhTron
Автор

I once wrote a Java program for a coding exercise task. It was supposed to run some algorithms, like computing the convex hull, on some input data. Algorithm to use was determined by a positional parameter.

So how do you do that? First, create an enum with constants for each algorithm, so that you can simply pass the argument as a string into the enum constructor to find the algorithm constant. Each constant had a string attached that contained the Java source code of said algorithm.

When the algorithm to use was determined, it took the string, fed that into the Eclipse Java compiler imported for that purpose, and stuffed the result into a byte array.
I then used a ByteArrayClassLoader to load the class from said byte array and accessed the method required via Reflection.

That was hilarious fun to review^^

luziferius
Автор

I never thought I could cry of laughter with a programming video yet here I am. The final one line trick was the icing on the cake.

nachosanz
Автор

Actually you can improve the doAnything function by instead of having boolean variables just let the function do all of them and if someone wants to do only some of the functionalities of the function he can always go to the function code and choose which lines to comment / uncomment in order for the function to do what he wants. The benefit of this method is that it would make your function have a lot of comments so it would be clearer.

tomerwolberg