How To Create Variables That Don't Suck - Writing Clean Java Code

preview_player
Показать описание
Tips on creating good names for your variables and methods in Java!
📕 One of my favorite programming books, Clean Code by Robert Martin
Or get the audio version FREE here with an Audible free trial!

Have you ever read a piece of Java code and thought, what is going on here?
Writing good variable and method names for your Java programs can make it much easier for others to quickly see what's going on, and is the first step to writing clean, readable code.

You just have to know what makes a good name first. In this beginner's Java tutorial video, we'll go over a variety of tips for creating good, meaningful variable names in Java.

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:

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

the first thing my prof in uni would teach us was clean code. Names, Comments, Javadoc, Invariants, low number of nested if statements, low number of parameters in functions, a maximum of 20 lines per function (use helper functions to make that work).

I hated doing all those things at first but the more I got into coding/programming the more I hated other people for not following these guidelines and how much I loved these guidelines

Pennervomland
Автор

John, you have helped me a lot. Thank you so much.

rajatpandey
Автор

I love how you explain things, in a very engaging way!
Please do a series on Design Patterns 🙏😇

AshrafZaman
Автор

I just learnt the basics of Java programming this semmester at uni and I just love learning more about it from your videos. Thank you very much!

carlosgas
Автор

My favorite YouTube channel these days

gone
Автор

Very important is using packages to organize the code, like if you have a lot of animal classes like dog, cat, parrot, etc. Make a package called AnimalClasses and put the 3 named above into it. Creates a clean hierarchy

thorbenjohr
Автор

unreadable code means the company can’t kick you out tho

OE
Автор

Although you did mention in passing the "oh, it was me!" bit, I think this particular point is never stressed upon enough when the subject of self-descriptive code (including good variable names) comes up in classes or tutorials. Back in my code auditing days, I always insisted a lot on this point — "Think of the poor guy who'll have to maintain this in six months!" "That guy is going to be YOU!".

Good, self-descriptive code eases you back in when you revisit it long after you first wrote it, without the context of its initial development in the short-term memory. A good name, a properly written loop, a good comment on a particular line (like «We don't need to check for a null value here because the constructor makes sure to replace any given null with "".») saves a LOT of time whenever doing maintenance, be the maintainer the guy who wrote it OR someone else.

Cheers! //

MiguelFarah
Автор

Seriously, I may actually pass my class because of you

NEnigma
Автор

You are videos are so simple and easy to understand.. Thank you

monisha
Автор

Hello John. Your tutorials are amazing. Thanks to You, I finally understand foundations of Java language, and I passed Exam for Java certificate. Keep going with java tutorials

danielzywalewski
Автор

2:15 damn you took my most commonly used variable name right out of my head

Supersoaker-xycr
Автор

I'm so happy that I discovered your channel some months ago. I have 2YOE working as a Software Engineer with Java and I love the way you share your ideas. Keep it up!

andres
Автор

I've watched several of these tutorials even though 1) I'm a veteran programmer 2) I've never had to use Java professionally. These are just good content. What would be a great short video is a tutorial to how to read documentation and why it is beneficial since a lot of beginners don't really leverage the benefits of that.

BoloH.
Автор

Great video as always, thanks! As an old subscriber of channels like Andertones and Rick Beato I did not immediately realize what I have a special confidence in this channel. Hope this makes sense ;)

The_Victr
Автор

I've been looking forward to a new episode the entire week. I wished you could do them more often.
As always, great content.
When instructors advise you to make methods to one thing only, I'm constantly reminded of my computer science training where one colleague who deemed himself good at programming, wrote a BlackJack game in a single method, i.e. the main method. The instructors were fascinated by the program actually working over the network and made no mention of the single method and more than a thousand lines of code.
Being a mathematician, he also used single letter or cryptic variable names.
You would really have liked to have his code as a perfect example of what not to do.

micleh
Автор

Clean Code (R.C.Martin) is a nice book for people trying to improve things like this

AnthonHax
Автор

Another tip of mine is that if a method's name is a yes/no question (ex: isValidInput) make it return a boolean. Please It makes code so much cleaner and more self-explanatory

Teloi
Автор

Another naming convention is to prefix method names that return boolean with ‘is’ or ‘has’. For example, isActive() [for a User class] or hasHorns() [for a class that extends Animal].

zepptonian
Автор

I'm loving each video of this channel.
Thank you for every video and your time! Excelent work.

himbazor