i recent been using my variables names like this

boolean is_dead = false;

turn out its not right. right conventions is

 boolean isDead = false;

for some reason i dont like the 2nd one. may be bc i been using 1st one for so long. i was wondering is there is different way of writeing variables and still be ok?

Recommended Answers

All 5 Replies

It's OK as long as you are consistent within a given code base though generally not recommended if it is meant to be consumed (used and read) by a wider audience (i.e. other Java developers). Also, in your case, you are better off with naming the variable as dead and the getter/accessor method named as isDead (if you have an accessor method that is).

IMO, just stick to the official Java coding convention and it should work out fine.

I agree with ~s.o.s~ The coding conventions he linked to are not mandatory, but they are the ones used most widely, particularly in all the Java API code. All working Java developers will be familiar with them, so if you want your code to be quickly and easily readable for a majority of programmers you should stick to them. If you start work as a Java coder your employer will have mandatory local coding standards that you will have to follow, and they will almost certainly have the same base.

I agree with ~s.o.s~ The coding conventions he linked to are not mandatory, but they are the ones used most widely, particularly in all the Java API code. All working Java developers will be familiar with them, so if you want your code to be quickly and easily readable for a majority of programmers you should stick to them. If you start work as a Java coder your employer will have mandatory local coding standards that you will have to follow, and they will almost certainly have the same base.

Yeah if u happen to find yourself in Rome, why not do what the Romans do.

even though naming conventions aren't just some "irrelevant annoying thinggy", loads of us out there 'll be very pleased if you didn't bother to follow naming conventions, but do always gave your variables logical names. believe you me,
boolean thread_still_running;
even though not following the naming convention, 'll be accepted a lot faster compared to your average:
boolean x;

The Sun (now Oracle) code conventions for Java are so universally accepted that it makes little sense to deviate from them without very good reason (working in an environment with a very large investment in some other technology where a smithering of Java is used on the side might be a place to do so, using the common conventions from that platform instead, but even there I'd advocate using the Java standards for Java most likely).

Not only is it good for the learner to get used to the conventions 99.99% of all Java code being produced follows, and which he'll almost certainly be expected to adhere to for the duration of his career writing Java code, but what code he writes and needs to be maintained by others will be much easier to read and maintain by those others if it is written in a format they instantly recognise (which is the reason for code conventions after all).

So just adhere to the Sun conventions, it'll safe you a lot of trouble later on.
And learn to use whatever is the commonly accepted standard for a platform when using that platform. You're using Java now, don't insist on using the Sun Java conventions when for example writing Fortran next year, use Fortran conventions when writing Fortran.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.