#Good programming practices.

15 messages · Page 1 of 1 (latest)

fierce merlin
#

Hey guys, i was solving a problem from an exercise and i did like this when declaring the variable.

double A, B, C;

A = sc.nextDouble();
B = sc.nextDouble();
C = sc.nextDouble();
        
double areaTriangulo, areaCirculo, areaTrapezio, areaQuadrado, areaRetangulo;

But in the solution the teacher did like this:

double A, B, C, triangulo, circulo, trapezio, quadrado, retangulo;
A = sc.nextDouble();
B = sc.nextDouble();
C = sc.nextDouble()

So i was thinking if my way of doing it is unecessary. I was thinking in making the code look clean. I'm still in early stages on Java so all the answers are really appreciate no matter how basic you may think the answer be.

steel dustBOT
#

This post has been reserved for your question.

Hey @fierce merlin! Please use /close or the Close Post button above when your problem is solved. 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.

somber dune
#

They are all doubles right?

fierce merlin
somber dune
#

Then both are okay. Except in your first one you are taking input from the user too

fierce merlin
#

Oh, he also takes it. Let me edit there.

somber dune
#

So it's fine then

fierce merlin
#

So it is just a matter of preference?

somber dune
#

Yeah but it's good declaring them First then come get it

indigo lintel
#

it doesn't matter in examples.
You can do either. So it's kinda a preference.
Typically you'd be following what's already in a codebase where some style is already established.

#

here's the official style conventions (from 1999 💀 )

fierce merlin
#

Ok, i see. Thank you for the help guys.

steel dustBOT
# fierce merlin Ok, i see. Thank you for the help guys.

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.