Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

darkwing

macrumors 65816
Jan 6, 2004
1,210
0
kingjr3 said:
Show me a C program that once compiled can run on a variety of platforms and architectures...Two languages, two different purposes. Assembly is faster than C, so using your failed logic it must be a better language?

What value are you even adding to the OP question??? Um, that would be none. :rolleyes:

He wants to know what language would make him make him marketable, not which language is bigger/faster/better....

Well, let's see. I did an independent study as an undergraduate where I wrote a computer game with openGL using SDL, a portable API to multimedia hardware. I demonstrated the game on three laptops: windows, mac, and linux all running side by side. SDL is ported to all three systems just as the JVM is ported to all three systems. It's the same premise, only it runs much much faster. The only downside is it requires a build on each machine. That's fine though. All those saved CPU cycles will more than make up for that as they add up over time. :) Would you like the source for it? That will meet your criteria just as well as Java does.

Sure I could have done the game in assembly, but it would have taken me much longer to do it. I could have done it in Java, too, but that also would have taken me longer. I know Java quite well, but I only use it when I need to make an applet for a web page. As far as I'm concerned, that's its only strong point.

The main reason I suggested the OP learn C++ is that it would aid in his transition to Objective-C should he pursue OSX development. However, there's no portable implementation of Obj-C that I know of, so he should start with basics. Besides, GUIs come later anyway.
 

cube

Suspended
May 10, 2004
17,011
4,973
darkwing said:
The main reason I suggested the OP learn C++ is that it would aid in his transition to Objective-C should he pursue OSX development.

C++ would only help in confusing him. Objective-C is a much simpler and better language.
C could be a stepping stone.
 

darkwing

macrumors 65816
Jan 6, 2004
1,210
0
cube said:
C++ would only help in confusing him. Objective-C is a much simpler and better language.
C could be a stepping stone.

You think objective-C is simpler? I'm curious as to why. Do you mean language syntax itself or using the Cocoa classes? I find the language to be rather straightforward but the classes took a while to digest. I think I should have bought a book. I have managed to write a few good cocoa apps for school, but they all have memory leaks. I didn't bother debugging them because nobody would ever notice. I want to get it all figured out though before the "next best thing" comes out. The real problem now is finding time, because I'm already swamped with a full time job (using c++!) and double time graduate coursework.
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
darkwing said:
The only downside is it requires a build on each machine. ...That will meet your criteria just as well as Java does.

Well if you have to build it, how is that portable? And SDL is just an API, not the entire C language API. The fact you have to compile a program on x86 and then recompile for say, PPC or SPARC, then that - my C loving friend, is not considered a portable language. So I guess that doesn't meet my criteria...Anyways, you're obviously drinking too much of the C kool-aid to understand that the two languages have two entirely different purposes and the demand for Java programmers is much much higher than that of C programmers.

PS - some performance comparisons for you - seems C isn't all you think it is, but then I am sure you will find failed logic or bad optimization in this guy's test programs.
 

darkwing

macrumors 65816
Jan 6, 2004
1,210
0
kingjr3 said:
Well if you have to build it, how is that portable? And SDL is just an API, not the entire C language API. The fact you have to compile a program on x86 and then recompile for say, PPC or SPARC, then that - my C loving friend, is not considered a portable language. So I guess that doesn't meet my criteria...Anyways, you're obviously drinking too much of the C kool-aid to understand that the two languages have two entirely different purposes and the demand for Java programmers is much much higher than that of C programmers.

PS - some performance comparisons for you - seems C isn't all you think it is, but then I am sure you will find failed logic or bad optimization in this guy's test programs.

Demand was higher for VB programmers once upon a time, and what happened to that language? You keep talking about "failed logic" and yet you yourself fail to grasp the simple reality of software layering. Let's review:

C program:

machine code

Java program:

machine code
JVM
bytecode

You also do not know the definition of a "portable" language.

http://en.wikipedia.org/wiki/C_programming_language

In reality, Java recompiles for your platform when you run something (JIT) which is the same thing as me doing it manually, therefore I guess Java must not be portable either.

Your link shows me a bar graph with no explanation of tests whatsoever. At the top it says "c++ sucks" so you expect me to think of this as some form of objective test site? Let's look at one of them...say, method call. Have you even read the JVM spec? In C++, even a virtual method call is simply an indirect jump from a class's vtable (which is defined statically). In Java, there's a whole lot more going on. If you have to use RTTI in C++, you should rethink your design. I always turn it off in my projects.

Outside of the web world, there is absolutely nothing that Java can do that C can't do, but there are a million things C can do that Java can't. Like write a JVM for example.

I can understand why people hate c++. It's got a lot of stupid ambiguities in it that can stump people. Of course, just because something is hard doesn't mean it sucks. Java has a lot of problems, too. For example, there's no equivalent for this:

void func(int **i)
{
*i = new int;
**i = 123;
}

Also, why does a language that claims to have no pointers have a NULL_POINTER_EXCEPTION? :rolleyes:
 

gekko513

macrumors 603
Oct 16, 2003
6,301
1
darkwing said:
Why would anyone do anything with java on a server side? Servers demand performance, and Java doesn't perform. I'm not saying you're wrong..I know they use it on the server side..however I think that runtime efficiency should always trump developer education.
Because often on the server side the demand for reliability, security, flexibility, scalability, development resources and maintainability is higher than the demand for performance on a single cpu. The overall performance is often more dependant on system design, I/O and scalability than on single threaded performance.
 

darkwing

macrumors 65816
Jan 6, 2004
1,210
0
gekko513 said:
Because often on the server side the demand for reliability, security, flexibility, scalability, development resources and maintainability is higher than the demand for performance on a single cpu. The overall performance is often more dependant on system design, I/O and scalability than on single threaded performance.

So what is inherent in the Java language that by defaults aids in scalability, I/O, or security? From a systems programming standpoint, a server running, say, Linux, is pretty good with I/O by default. Scalability? Java doesn't help you write threads that parallel well together, so using just pthreads or something similar is going to have the same issues. In most servers, there isn't really any parallel programming but rather threads dispatched to other CPUs or machines to aid in overall processing..so that has to be coded as well. Security? Java has some security mechanisms but my only experience with those is signing a .jar file with a bogus certificate so my online game project would work.

If you'd like to inform me I'd be glad to read it.
 

gekko513

macrumors 603
Oct 16, 2003
6,301
1
darkwing said:
void func(int **i)
{
*i = new int;
**i = 123;
}
No?

void doSomethingVeryStrange(ObjectHolder i) {
i.obj = new MutableInteger();
((MutableInteger)i.obj).value = 123;
}

class ObjectHolder {
public Object obj;
}

class MutableInteger {
public int value;
}

But what does this code solve?
 

darkwing

macrumors 65816
Jan 6, 2004
1,210
0
Lol sorry. I misread your code. I shouldn't have said there was no equivalent to what I did. I should have said it requires messy wrapper classes. Also, making data members public is a no no. :)
 

gekko513

macrumors 603
Oct 16, 2003
6,301
1
darkwing said:
Wow, an intelligent answer. Thanks.

So what is inherent in the Java language that by defaults aids in scalability, I/O, or security? From a systems programming standpoint, a server running, say, Linux, is pretty good with I/O by default. Scalability? Java doesn't help you write threads that parallel well together, so using just pthreads or something similar is going to have the same issues. In most servers, there isn't really any parallel programming but rather threads dispatched to other CPUs or machines to aid in overall processing..so that has to be coded as well. Security? Java has some security mechanisms but my only experience with those is signing a .jar file with a bogus certificate so my online game project would work.

If you'd like to inform me I'd be glad to read it.
I forgot to add that I don't necessarily think Java is always better for scalability, security and the other things I mentioned.

I'm just saying that single threaded performance isn't often the most important aspect to consider for server side programs. Java, C++ and other languages can have different strengths and in the end the choice of platform should depend on a weighted analysis of the advantages important to the task at hand.

I forgot the deployment environment as a variable in the equation. Application servers and such can fill in for a lot of the routine tasks in a server situation and make the development a lot easier.

darkwing said:
Lol sorry. I misread your code. I shouldn't have said there was no equivalent to what I did. I should have said it requires messy wrapper classes. Also, making data members public is a no no. :)
But a C pointer is a public data member. I was just replicating the functionality. :p
 

darkwing

macrumors 65816
Jan 6, 2004
1,210
0
gekko513 said:
I forgot to add that I don't necessarily think Java is always better for scalability, security and the other things I mentioned.

I'm just saying that single threaded performance isn't often the most important aspect to consider for server side programs. Java, C++ and other languages can have different strengths and in the end the choice of platform should depend on a weighted analysis of the advantages important to the task at hand.

I forgot the deployment environment as a variable in the equation. Application servers and such can fill in for a lot of the routine tasks in a server situation and make the development a lot easier.

Well this may be my mistake, then. I figure that when you are setting up a server you want to keep the idea in mind that vast numbers of users may be using this, and you want as much room for growth as possible.

The only reason I see that Java has become popular is because it's "easier" to learn, and was hyped this way from the start, so a lot of people learned it. I'm also biased against Java because GridBagLayout sucks. :)

gekko513 said:
But a C pointer is a public data member. I was just replicating the functionality. :p

How is something not inside a class a public data member? :p

In my software engineering 2 course last year as an undergrad, we had to take a red/black tree C implementation and re-write it as Java. My friend and I had a race on it. I finished it in 2 hours, 20 minutes, and he finished it in about 2 hours and 40 minutes. What's funny is most people took a week+ to do it. The part that stumped everybody was the int** stuff. My friend and I both recognized it right away. I actually had to write a wrapper class because at the time 1.5 wasn't available for OSX, so I couldn't use AtomicInteger which would give me the functionality I needed. He got away with using that, the cheater.

I should point out, btw, that given the input from the teacher, the C version on my 1.5 ghz powerbook g4 ran the program in about 60 ms. The java version took about 1050 ms. On my friend's windows laptop (which isn't nearly as fast as my G4), it was about a 3:1 advantage for C using my java code. This goes to show why the OSX JVM stinks.
 

gekko513

macrumors 603
Oct 16, 2003
6,301
1
darkwing said:
How is something not inside a class a public data member? :p
Of course it's not a public data member. It's not a member since it's not a class.

But the functionally equivalent to sending a pointer to pointer as a parameter to a function is sending a reference to an object with public data members.
 

gekko513

macrumors 603
Oct 16, 2003
6,301
1
darkwing said:
Well this may be my mistake, then. I figure that when you are setting up a server you want to keep the idea in mind that vast numbers of users may be using this, and you want as much room for growth as possible.
Of course you do and that's why Java sometimes may be a good choice.

How much will it cost me to develop, set up and maintain a server system capable of serving 1000 transactions per minute the first year and then scale to a maximum of 10000 by the third year.

Sometimes the cheaper alternative will be Java. Sometimes it won't.

Edit: Hardware is most often the cheap part of the equation. Many server apps need to scale well over a server cluster. Adding nodes is cheap compared to other costs.
 

mwpeters8182

macrumors 6502
Apr 16, 2003
411
0
Boston, MA
Yeah, java performance is absolutely putrid in OS X. I have no idea why, but I'd think it was something that apple would have fixed by now.

As for the C++/Java debate, I do most of my programming in C++, because it's what I'm most comfortable with. I've done some java, but for scientific computing, I'm always interfacing with C++ (or FORTRAN, yikes).

I think it's a matter of what you want to do with the language - Java's better for some things, C/C++ is better for otheres.
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
kingjr3 said:
Well if you have to build it, how is that portable? And SDL is just an API, not the entire C language API. The fact you have to compile a program on x86 and then recompile for say, PPC or SPARC, then that - my C loving friend, is not considered a portable language.
i've been reading but avoiding the c++ vs. java question. i've programmed both professionally (6 years c++, 2 years java), but i've been out of the industry for 6 years now.

HOWEVER -- i did want to address this notion of portability. i contend that C is, in fact, a portable language. in programming language context, 'portable' simply means 'able to be ported'. it doesn't, imo, imply any level of automatic-ness. in fact, it can be a real PITA.

that java hides a good bit of it doesn't change the definition. all imo, of course.
 

darkwing

macrumors 65816
Jan 6, 2004
1,210
0
kingjr3 said:
Its the link at the top of the page. :rolleyes:

http://kano.net/javabench/index

Don't worry. You'll grow out of it someday. Some of us just do it faster than others. :)

gekko513 said:
Of course you do and that's why Java sometimes may be a good choice.

How much will it cost me to develop, set up and maintain a server system capable of serving 1000 transactions per minute the first year and then scale to a maximum of 10000 by the third year.

Sometimes the cheaper alternative will be Java. Sometimes it won't.

Edit: Hardware is most often the cheap part of the equation. Many server apps need to scale well over a server cluster. Adding nodes is cheap compared to other costs.

Well my problem with the notion that Java is cheaper to develop than C++ or even to maintain than C++ is that what it really boils down to is what your people know. I'd be much faster at c++ than at Java for just about everything when it comes to my development time. I know both really well, and I see nothing in Java that's going to speed things up significantly for me. The only nice thing about Java is that there is basically a central repository of code that handles things for me, and I don't have to "hunt" for things as much. However, I almost always write my own code anyway and so the only thing Java has, as a "native" component, helped me with, is displaying JPEG files.

zimv20 said:
i've been reading but avoiding the c++ vs. java question. i've programmed both professionally (6 years c++, 2 years java), but i've been out of the industry for 6 years now.

HOWEVER -- i did want to address this notion of portability. i contend that C is, in fact, a portable language. in programming language context, 'portable' simply means 'able to be ported'. it doesn't, imo, imply any level of automatic-ness. in fact, it can be a real PITA.

that java hides a good bit of it doesn't change the definition. all imo, of course.

It isn't really your opinion. You've just given the definition of a portable language. Good for you.:)
 

gekko513

macrumors 603
Oct 16, 2003
6,301
1
darkwing said:
Well my problem with the notion that Java is cheaper to develop than C++ or even to maintain than C++ is that what it really boils down to is what your people know. I'd be much faster at c++ than at Java for just about everything when it comes to my development time. I know both really well, and I see nothing in Java that's going to speed things up significantly for me. The only nice thing about Java is that there is basically a central repository of code that handles things for me, and I don't have to "hunt" for things as much. However, I almost always write my own code anyway and so the only thing Java has, as a "native" component, helped me with, is displaying JPEG files.
Yeah, what your people know, but also what libraries and available deployment environments has to offer for the project in question.

Sometimes C++ is the better choice.

I've been responsible for 3 rather small scale server type deployments. One in Java, one in C++ and one with a core of Java and C++ modules for performance critical computation.

darkwing said:
I'm also biased against Java because GridBagLayout sucks. :)
What?! GridBagLayout is gods gift to the programmer!
 

cube

Suspended
May 10, 2004
17,011
4,973
gekko513 said:
What?! GridBagLayout is gods gift to the programmer!

All popular GUI toolkits suck. They are really primitive.

If you want to see something that really rules for programming, check out CMU's Garnet (for Common Lisp). Because of silly budgetary reasons, they later
moved their focus to a C++ version called Amulet. Of course, the Common Lisp version is way better. In fact, I think Amulet is horrible, because of the constraints imposed by the language, but I would much rather use it than something like Swing, zApp, whatever.

There is no more funding for Amulet. Nor for a Java version.
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
i changed my mind. i am going to comment.

my area of focus was the server tier in a 3-tier client/server architecture. i'm going to highlight two specific projects:

1. in 1997, i was the architect and lead developer for the server-side portion of a trading app. it was a c++/corba project. the server executables were deployed on a relatively slow Sun box running solaris. the ORB vendor was orbix. the client side (which i wasn't a part of) was an absolute mess of a project, done in c++ and running on relatively fast PCs running Windows NT.

this was a complicated server piece. it maintained entire domain models for clients and ran fairly complex calculations on them. user actions meant a lot of db reads and saves (Sybase). there was a lot going on.

2. in 1999, i was the lead developer for the server-side side portion of another trading app, much simpler than the above. this project was written in Java. both client and server tiers ran on fast NT boxes. the database was Oracle (iirc). client and server tier communication was RMI/IIOP. the ORB vendor was visigenics.

this was a simple server piece. the app was mostly a screen scrape with a few server-side calculations. i wasn't the architect here but i often wondered why we couldn't get away with 2-tier.

.....

on project 1, i never once got a complaint about performance. project 2 was a performance nightmare.

granted, project 2 was nearly 7 years ago, and i'm sure much has changed (including faster machines). but it was interesting to me how a much more complicated c++ app on slow sun servers could beat the pants off a simple java app on faster NT machines.

i've no idea if java's reputation for slowness is deserved today, but it was in 1999.

edit: changed db vendor in project 2 from sybase to oracle. i believe that's correct, though my memory is a bit fuzzy.
 

darkwing

macrumors 65816
Jan 6, 2004
1,210
0
gekko513 said:
Yeah, what your people know, but also what libraries and available deployment environments has to offer for the project in question.

Sometimes C++ is the better choice.

I've been responsible for 3 rather small scale server type deployments. One in Java, one in C++ and one with a core of Java and C++ modules for performance critical computation.

Uh oh. C++ modules. Now you lose the "portability". Some members will be upset and say that isn't real java! :rolleyes:

I wrote an online game for a class project last year (2 games in one year for school credit! fun stuff) and I used a c++ server running on Linux and a java applet for a client. Fun stuff.

gekko513 said:
What?! GridBagLayout is gods gift to the programmer!

You're crazy. :p The two times I've used it both took me about 4 hours to correctly get things to line up/display right. Having to set the weightx to 1 sometimes and 0 others and having things resize on their own when clicked..ugh. I hate it. :p
 

cube

Suspended
May 10, 2004
17,011
4,973
For the C++ fans: I would take a look at Amulet and see it can be made better today by using the boost libraries (lambda et al).
 

darkwing

macrumors 65816
Jan 6, 2004
1,210
0
zimv20 said:
i've no idea if java's reputation for slowness is deserved today, but it was in 1999.

What is an ORB vendor? (I'm a hard realtime embedded systems guy, not a server guy.)

I know that Sun spent most of their money and resources on the Windows JVM, for popularity reasons. It outperforms all other versions from what I've read, even the Sun version. I don't know if this was the case 7 years ago, but today it seems to be such. Anyone ever play defender? That 80s arcade game? My friend made a simple java app that does side scrolling and the random mountain-lines in the background. On his p3 windows machine, it took about 10-15% of the CPU and was smooth as silk. On my at the time 1ghz G4 powerbook it took 100% of the CPU and was very choppy.

It's hard to see any Mac user on here defending the performance of Java when we're given such a crappy JVM by Apple.

Interesting story about your server projects. When you talk about a trading app did you mean stocks? Forex?

cube said:
For the C++ fans: I would take a look at Amulet and see it can be made better today by using the boost libraries (lambda et al).

I googled around for it and their home page seems to have not been updated since the late 90s. I'm thinking I won't bother. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.