#Sorting Visualiser in Terminal | Code Review

33 messages Β· Page 1 of 1 (latest)

sick spindle
#

Hi all,

I have been working on a sorting algorithm that is animated similarly to how the YouTube videos do it in the terminal.

I've finally implemented the display, animation and bubble sort algorithm, I was hoping you guys could do a code review as I am still learning Java

Find it here: https://github.com/jacoboneill/learning-programming/tree/main/practice-projects/sorting-algorithm-visualiser-tui

Jacob

GitHub

Contribute to jacoboneill/learning-programming development by creating an account on GitHub.

peak creekBOT
#

βŒ› This post has been reserved for your question.

Hey @sick spindle! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

peak remnant
#

The first 2 things that I see right off the bat, you're not taking advantage of OOP principles. That's what Java was meant to do, and not using objects kind of defeats the purpose of the language and goes against the standard.

#

The second thing, when you close a Scanner, it also closes the underlying input stream, in your case it's System.in which you never want to do.

#

If it were let's say a FileInputStream, then yes, you'd want to close it. But you should never close System.in

Let the JVM handle that for you.

#

Other than that, your code is pretty nice and it's very readable which is great.

#

@sick spindle

sick spindle
peak remnant
#

I dont really see any functional programming either. You should definitely read up on OOP.

#

You should almost never use the static keyword. It's situational, but you seem to be using it for every function in every class.

#

Which is not OOP.

#

The fundamentals of OOP would be encapsulation, abstraction, inheritance and polymorphism.

#

Would also be nice to see some design patterns being implemented.

sick spindle
# peak remnant The second thing, when you close a Scanner, it also closes the underlying input ...

Also, the only reason I used scanner.close() is because the Java FreecodeCamp course told me to (https://www.youtube.com/watch?v=A74TOX803D0&t=4602s)

Learn the Java programming language in this complete beginner's course. You will learn all the main features of Java (version 17) and how to use Java for your own projects.
πŸ”— Code along on Replit: https://join.replit.com/java-students

✏️ Farhan Hasin Chowdhury created this course.

πŸ— Replit provided a grant that make this course possible.

πŸ”— h...

β–Ά Play video
peak remnant
#

You should close your scanners for sure, just not if it's using System.in as the underlying input stream

sick spindle
#

@peak remnant So took make it more OOP what would you change to my program?

peak remnant
#

You should read up on it, I didn't see any of the OOP fundamentals implemented in your project at all. πŸ˜›

#

I'm not trying to be mean, the code is very well written I'm just trying to teach you something.

#

You should start with OOP fundamentals, and then read in to design patterns.

sick spindle
#

I know but, for example, the Display class is static because you would only have one display. Would it be more in the style of OOP for it to be instantiated and use constructors and stuff?

#

Also, @peak remnant is there any videos about OOP fundamentals and design patterns that you would reccomend?

peak remnant
#

For OOP, I would recommend you do the MOOC modules from the University of Helsinki

#

And for design patterns, this is the most beautifully written thing in the world

https://refactoring.guru/design-patterns

sick spindle
#

@peak remnant Thank you for the information πŸ™‚

peak creekBOT
peak remnant
#

πŸ₯°πŸ₯°

sick spindle
#

@peak remnant I'll read these soon and get back to you

peak remnant
#

Cool πŸ™‚

sick spindle
#

@peak remnant Is there anything else you would recommend?

peak remnant
#

I think those resources will give you plenty of reading for a while πŸ˜›

sick spindle
#

@peak remnant Thank you