Moving from Java to C++

Programming, for all ages and all languages.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: Moving from Java to C++

Post by Colonel Kernel »

C# has pointers, but they are often overlooked. You can only use them in methods or code blocks marked as "unsafe", and you have to use a "fixed" statement (IIRC) to pin memory so the GC doesn't move it before you can get a pointer to it.

IMO, if an OS kernel (Singularity) can be written in C#, then it's just a matter of time before it becomes more broadly applicable to systems programming. The language need not (and does not) drag the entire .NET environment around with it.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
steveklabnik
Member
Member
Posts: 72
Joined: Wed Jan 28, 2009 4:30 pm

Re: Moving from Java to C++

Post by steveklabnik »

Love4Boobies wrote:I find it a bit ackward that everyone's talking about the death of C++ but (AFAIK) no one has ever mentioned the death of C. Why's that?
People have already given good reasons as an answer to this, but I figured I'd chime in with Linus Torvalds and his opinion.

There's actually quite a bit of 'pro-c, anti-c++' sentiment, which I am admittedly a part of... the previous posters covered the topic pretty well, I think.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Moving from Java to C++

Post by Love4Boobies »

Colonel Kernel wrote:IMO, if an OS kernel (Singularity) can be written in C#, then it's just a matter of time before it becomes more broadly applicable to systems programming. The language need not (and does not) drag the entire .NET environment around with it.
Maybe. IMO that wouldn't be the best move. Perhaps it would be most wise (and fast) to just come up with a CIL CPU (don't forget that there are already Java CPUs out there). I'm aware of the compatibility issues raised by this, but if we really reach that point, even x86 could execute CIL running say, CIL Mode, instead of pmode or long mode or whatever... Hardware is finally starting to be software-driven these days (look at what they're doing at PARLAB, Berkeley).
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Moving from Java to C++

Post by Solar »

steveklabnik wrote:People have already given good reasons as an answer to this, but I figured I'd chime in with Linus Torvalds and his opinion.
Personally, when I look for a good piece of BS to laugh about, I take The Linux Kernel Mailing List FAQ, chapter 15-3. Those guys are a serious case of xenophobia, and don't know bollocks about C++. I mean, it would be OK if they said "we're mostly C guys here, and don't know C++ really, so we stick to C". I could totally relate to that. But the FUD I see in that post of Linus, and in the FAQ, would be a crying matter if it weren't so funny.

Let's see. What are Linus' points?
  • C++ coders are crap and C coders are great.
  • Coding in C++ "invariably" leads to using the STL and Boost libraries.
  • Coding in C++ "invariably" leads to bad abstractions your code depends on, so you have to rewrite your object model sooner or later. Coding in C doesn't.
  • C++ code is less maintainable than C.
That's what he says, between all that "BS" and "piss off" he seems so fond of. I won't even honor that list with a reply.

The LKML FAQ is even better:
  • Writing C code so it can be compiled by a C++ compiler results in performance loss. (Hint: You don't have to compile everything in g++, it's about being able to do so.)
  • Drivers cannot be written in C++ because the kernel headers don't support it. (See next point.)
  • We won't make the kernel headers support C++ because there aren't any C++ drivers around. (See previous point.)
  • We won't make the kernel headers support C++ because it's (insert smartass find-and-count) so many lines of code and we are too stupid to do a find-and-replace of C++ keywords using a similar technique as we used for counting code lines.
  • C++ coders are too stupid to accept a limitation like -fno-exceptions.
That, together with the general attitude that C++ coders are somehow less brilliant than C coders because they do not follow the true path (hallowed are the Ori), originally convinced me that the Linux kernel maintainers are simply another bunch of arrogant twits.
Last edited by Solar on Thu Jan 29, 2009 6:45 am, edited 1 time in total.
Every good solution is obvious once you've found it.
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

Re: Moving from Java to C++

Post by DeletedAccount »

Hi,
All the so called hacker 'demi gods' are arrogant . I have met one of them , I was one of the starting members of the open source community in my college . I have already told you in pm what happened , that had a big impact on my carrier desicion later .

Regards
Shrek
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: Moving from Java to C++

Post by Colonel Kernel »

Love4Boobies wrote:Maybe. IMO that wouldn't be the best move.
"Maybe" it will take the world by storm, or "maybe" it's possible? I can tell you that it's possible because it's already been done.

Why don't you think it's the best move?
Love4Boobies wrote:Perhaps it would be most wise (and fast) to just come up with a CIL CPU (don't forget that there are already Java CPUs out there). I'm aware of the compatibility issues raised by this, but if we really reach that point, even x86 could execute CIL running say, CIL Mode, instead of pmode or long mode or whatever... Hardware is finally starting to be software-driven these days (look at what they're doing at PARLAB, Berkeley).
CPUs are designed the way they are for a lot of good reasons of which software people are usually ignorant. Java CPUs are slow because they're stack machines and can't take advantage of techniques like out-of-order execution, at least not without translating the bytecode into some internal register-based machine code. What's the point if x86 CPUs already do this? The decoding logic to do this is no longer such a big overhead compared to all the other pipeline stages in a modern x86 CPU.
steveklabnik wrote:People have already given good reasons as an answer to this, but I figured I'd chime in with Linus Torvalds and his opinion.
Linus' opinion doesn't count for much around here. :D As Solar said, a lot of what he has to say on the subject is uninformed FUD. His personal style (bombastic, rude, arrogant) makes it difficult to take anything he has to say very seriously. Too bad for him IMO.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Moving from Java to C++

Post by Love4Boobies »

@CK: Then maybe a new design will help: a safe bytecode that can take advantage of different techniques that boost performance. I'm fairly sure it can be done but I'm just as sure it won't... :(
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Moving from Java to C++

Post by Solar »

Tao Group has a mechanism where code is compiled for a virtual processor, which gets translated to native on-the-fly by the executable loader. That way, you have fully portable executables which still benefit fully from native CPU architecture. The loader was faster at this translation than the hard drive in loading the code, or so they claimed.

All of this heavily patented and IP'd, of course...
Every good solution is obvious once you've found it.
User avatar
steveklabnik
Member
Member
Posts: 72
Joined: Wed Jan 28, 2009 4:30 pm

Re: Moving from Java to C++

Post by steveklabnik »

Colonel Kernel wrote:Linus' opinion doesn't count for much around here
Well, I don't take what Linus says as gospel, either. And I certainly don't want to hijack this thread, and turn it into the C vs C++ thread...I also don't even 100% agree with what Linus is saying. I just figured that I'd add in another, slightly different opinion.

I personally feel that C++ doesn't add anything that I feel is really useful over C. I prefer really low level, simple languages, or really high level, complicated languages. The middle ground ones, not so much. This is one reason I don't really like Java, either...
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Moving from Java to C++

Post by Solar »

steveklabnik wrote:I personally feel that C++ doesn't add anything that I feel is really useful over C.
Hard to answer to that without completely hijacking the thread. I think different. ;-)
Every good solution is obvious once you've found it.
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Moving from Java to C++

Post by AndrewAPrice »

I had the opportunity to use a pure C project (no C++) and it was certainly different.

I know you could imitate C++'s behaviour since this class:

Code: Select all

class MyClass
{
public:
       MyClass();
       ~MyClass();
       int DoStuff(int param);
private:
       float IAmAFloat;
};
as

Code: Select all

typedef struct sMyClass
{
       float IAmAFloat;
} MyClass;

MyClass *MyClass_New();
void MyClass_Destroy(MyClass *this);
int MyClass_DoStuff(MyClass *this, int param);
Which I found myself doing a lot. And the code became untidy - but I believe that's just my perception after being so use to classes.
My OS is Perception.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Moving from Java to C++

Post by Solar »

You could make function pointers members of that struct...

But that's beside the point. In the big bag of classes, exceptions, templates, namespaces, function overloading, and type safety, there should be something for anybody.
Every good solution is obvious once you've found it.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: Moving from Java to C++

Post by Colonel Kernel »

Love4Boobies wrote:@CK: Then maybe a new design will help: a safe bytecode that can take advantage of different techniques that boost performance. I'm fairly sure it can be done but I'm just as sure it won't... :(
What makes you think that such a thing doesn't exist already? Take a look at Bartok, a compiler project by MS research. It is able to apply very powerful interprocedural optimizations to IL and compile it to very efficient native code.

I think you may be conflating performance issues and IL in your mind. :) Think more carefully about where you think the bad performance is coming from....
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Moving from Java to C++

Post by Love4Boobies »

Colonel Kernel wrote:
Love4Boobies wrote:@CK: Then maybe a new design will help: a safe bytecode that can take advantage of different techniques that boost performance. I'm fairly sure it can be done but I'm just as sure it won't... :(
What makes you think that such a thing doesn't exist already? Take a look at Bartok, a compiler project by MS research. It is able to apply very powerful interprocedural optimizations to IL and compile it to very efficient native code.

I think you may be conflating performance issues and IL in your mind. :) Think more carefully about where you think the bad performance is coming from....
I know of Bartok. Disadvantages:
  • Some overhead, as you suggest, maybe not large.
  • Another layer between software and hardware. That can mean trouble (read: bugs).
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Moving from Java to C++

Post by Combuster »

Another layer between software and hardware. That can mean trouble (read: bugs).
BS. The same amount of layers as Java or .NET or LLVM has: source->bytecode->native code.
Some overhead, as you suggest, maybe not large.
It has a larger setup cost, yes. But after that the win is much larger than any other language since using bartok results in the privilege to run completely unprotected, and thus, without the repeated overhead incurred by protection layers.


As Colonel Kernel would say: go read the research papers.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply