Moving from Java to C++
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re: Moving from Java to C++
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.
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:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
- steveklabnik
- Member
- Posts: 72
- Joined: Wed Jan 28, 2009 4:30 pm
Re: Moving from Java to C++
People have already given good reasons as an answer to this, but I figured I'd chime in with Linus Torvalds and his opinion.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?
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.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Moving from Java to C++
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).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.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: Moving from Java to C++
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.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.
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.
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.
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.
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
Re: Moving from Java to C++
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
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
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re: Moving from Java to C++
"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.Love4Boobies wrote:Maybe. IMO that wouldn't be the best move.
Why don't you think it's the best move?
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.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).
Linus' opinion doesn't count for much around here. 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.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.
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Moving from Java to C++
@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 ]
[ Project UDI ]
Re: Moving from Java to C++
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...
All of this heavily patented and IP'd, of course...
Every good solution is obvious once you've found it.
- steveklabnik
- Member
- Posts: 72
- Joined: Wed Jan 28, 2009 4:30 pm
Re: Moving from Java to C++
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.Colonel Kernel wrote:Linus' opinion doesn't count for much around here
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...
Re: Moving from Java to C++
Hard to answer to that without completely hijacking the thread. I think different.steveklabnik wrote:I personally feel that C++ doesn't add anything that I feel is really useful over C.
Every good solution is obvious once you've found it.
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
Re: Moving from Java to C++
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:
as
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.
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;
};
Code: Select all
typedef struct sMyClass
{
float IAmAFloat;
} MyClass;
MyClass *MyClass_New();
void MyClass_Destroy(MyClass *this);
int MyClass_DoStuff(MyClass *this, int param);
My OS is Perception.
Re: Moving from Java to C++
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.
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.
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re: Moving from Java to C++
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.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...
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:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Moving from Java to C++
I know of Bartok. Disadvantages:Colonel Kernel wrote: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.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...
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....
- 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 ]
[ Project UDI ]
- Combuster
- 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++
BS. The same amount of layers as Java or .NET or LLVM has: source->bytecode->native code.Another layer between software and hardware. That can mean trouble (read: bugs).
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.Some overhead, as you suggest, maybe not large.
As Colonel Kernel would say: go read the research papers.