Fedora Linux Support Community & Resources Center
  #1  
Old 13th January 2009, 05:55 AM
tashirosgt Offline
Registered User
 
Join Date: Aug 2004
Posts: 3,855
What does Java tell about good C++ practices?

Like all languages, Java was designed to fix certain problems in older languages. When I compare it to C++, I think the designers also wanted to make certain "best practices" in C++ mandatory. Examples would be that the file name that holds the code for the class must express the name of the class and that class files are in a sensible directory structure. Java also wants all the code for a class to be in one file. I suppose with modern editors that isn't such a burden to do in C++. What other "best practice" hints can a C++ programmer take from Java?
__________________
"Never let the task you are trying to accomplish distract you from the study of computers."
Reply With Quote
  #2  
Old 13th January 2009, 10:38 AM
adrianx's Avatar
adrianx Offline
Registered User
 
Join Date: Jul 2007
Location: South Africa
Posts: 953
I don't know so much if this is a standard best practice in Java, but it has certainly helped me a lot (with my own code). Class names *always* start with an upper case letter - SomeClass. Object names and methods (functions) *always* start with a lower case letter - someClass.someMethod().
__________________
Registered Linux User 460110
Reply With Quote
  #3  
Old 13th January 2009, 05:19 PM
stevea's Avatar
stevea Offline
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,300
I don't think imposing class names onto the files or a language imposing a directory structure is a "best practice" at all. It may be a reasonable choice for most cases but hardly a best practice. If you've worked on some very large C++ projects you'd see these rules as unnecessarily confining.

They didn't create a cpp C-preprocessor which is a good thing, but everyone knows that. The Cpp applied to C++ allows a lot of type hiding and bad practices. It's not some brilliant revelation.


The *CONVENTIONS* for capitalization and lower case objects etc is not enforced. I've had co-workers argue strenuously against CamelCase (tho' I like it personally). In any case the important thing is to have some consistent convention and use it consistently. It's perhaps a best practice for Java developers to follow the convention used in the Java libraries and predefines .. but those original choices don't represent "best practices" just good choices among many.



The lack of pointers in java is an artifact of it's architectural independence. You'd can find some very strong arguments that pointers are bad in structured code, and equally persuasive arguments that they are powerful and efficient. The lack of class inheritance is perhaps from a similar "limitation" origin or to reduce implementation complexity.

Nah - I can't agree. IMO Java is a good language clearly based on C++ with several self-imposed limitations to meet it's more limited environment. I think you are reading too much into the differences.
Reply With Quote
  #4  
Old 13th January 2009, 05:27 PM
sej7278 Offline
Registered User
 
Join Date: Sep 2004
Posts: 2,008
Quote:
Originally Posted by stevea View Post
Nah - I can't agree. IMO Java is a good language clearly based on C++ with several self-imposed limitations to meet it's more limited environment. I think you are reading too much into the differences.
exactly, java is too confined as its designed to run on the jvm, instead of hardware.

i wouldn't mind so much if it were truly portable, but as "write once, run anywhere" is complete BS, i prefer C++ without the limitations.
Reply With Quote
  #5  
Old 13th January 2009, 06:24 PM
aleph's Avatar
aleph Offline
Banned (for/from) behaving just like everybody else!
 
Join Date: Jul 2007
Location: Beijing, China
Posts: 1,307
Quote:
Originally Posted by sej7278 View Post
exactly, java is too confined as its designed to run on the jvm, instead of hardware.
Actually some ARM processors can run some Java bytecode natively. That's one of the reasons why Java is prevailing on mobile phones.
__________________
I believe in nerditarianism. I read FedoraForum for the Fedora-related posts.
Reply With Quote
  #6  
Old 13th January 2009, 06:45 PM
stevea's Avatar
stevea Offline
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,300
Quote:
Originally Posted by sej7278 View Post
exactly, java is too confined as its designed to run on the jvm, instead of hardware.

i wouldn't mind so much if it were truly portable, but as "write once, run anywhere" is complete BS, i prefer C++ without the limitations.

So why is it complete BS ? Could you explain your comment please. My impression was always that Java bytecode was pretty d*mned portable assuming you have a JVM running on the target and all the right versions. So why do you say this ?

Now until recently the boneheads (my opinion) at Sun have prevented anyone from porting a JVM beyond the PCs, Sparc and a very few others. The open source stuff and the GNU gjc have largely broken that bottleneck (I believe).
Reply With Quote
  #7  
Old 14th January 2009, 09:49 PM
richfell Offline
Registered User
 
Join Date: Oct 2008
Posts: 20
Quote:
Originally Posted by stevea View Post
So why is it complete BS ? Could you explain your comment please. My impression was always that Java bytecode was pretty d*mned portable assuming you have a JVM running on the target and all the right versions. So why do you say this ?

...
IMO, it's more like write once, debug everywhere. The issue is not the byte codes, its the varying behavior on different HW/SW platforms when running the code.
Reply With Quote
  #8  
Old 24th January 2009, 06:03 AM
stevea's Avatar
stevea Offline
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,300
Quote:
Originally Posted by richfell View Post
IMO, it's more like write once, debug everywhere. The issue is not the byte codes, its the varying behavior on different HW/SW platforms when running the code.
Sorry it taken so long to get back to this ... but can you please explain in more detail. The whole point of the JVM was to prevent varying behavior on different platforms. I've written just a little Java (starting back circa 1995) and have never deployed anything serious cross-platform so maybe I'm missing the practical issue here.

Are the JVM models defective ?
Reply With Quote
  #9  
Old 24th January 2009, 10:30 AM
sej7278 Offline
Registered User
 
Join Date: Sep 2004
Posts: 2,008
i think the problem lies in the different levels of quality or support of the jvm's, if your platform is not well supported then you'll only have a subset of the functionality.

i've almost never seen a .jar from one platform "just work" on another.

the same can't be said for other interpreted languages though - look at python, ruby, php or perl, you get almost 100% cross-platform capability.
Reply With Quote
  #10  
Old 24th January 2009, 01:07 PM
aleph's Avatar
aleph Offline
Banned (for/from) behaving just like everybody else!
 
Join Date: Jul 2007
Location: Beijing, China
Posts: 1,307
Here's two links to some quite amusing, albeit somewhat inflammatory, quotes regarding Java and C++...

http://harmful.cat-v.org/software/java
http://harmful.cat-v.org/software/c++/

Well, just for your laugh... My personal favorate is "The last good thing written in C++ was the Pachelbel Canon."
__________________
I believe in nerditarianism. I read FedoraForum for the Fedora-related posts.

Last edited by aleph; 24th January 2009 at 02:16 PM.
Reply With Quote
Reply

Tags
good, java, practices

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need suggestions on a good Java Text greenneub Programming & Packaging 2 21st July 2009 10:01 PM
Good Computer Practices SlowJet Fedora Focus 2 4th April 2006 03:36 AM
Good Java Book guyverlord3 Programming & Packaging 3 26th August 2005 03:32 PM
java apps don't look good help needed... granville86 Using Fedora 2 18th July 2005 12:37 AM
Good Java Editor/IDE? BandC Programming & Packaging 9 27th June 2005 08:52 AM


Current GMT-time: 11:29 (Monday, 20-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat