Culture shock

I've got quite a bit of C++ down (thought there is no way I know everything), and have some minor experience in Java and C#.

So, for anyone who knows another language in addition to C++, what would you say is the hardest bit for transition either way?

From Java to C++, I'd say Memory Management/Pointers, Templates, and Multiple Inheritance.

From C++ to Java, I'd say the lack of MI, lack of Enums, Memory Management, and everything being declared in a class. In fact, the one thing I can't wrap my head around is why Sun decided to force everything to be declared in a class.
The hardest transitions are cross-paradigm transitions: every little bit is different. Look at Haskell or Scheme, Prolog or Erlang, APL or J

the one thing I can't wrap my head around is why Sun decided to force everything to be declared in a class

That's the legacy of the original OOP schism betwen Simula's "objects model a physical world" and Smalltalk's "everything is an object". C++ and Java chose different object models.
closed account (zb0S216C)
Whovian wrote:
"So, for anyone who knows another language in addition to C++, what would you say is the hardest bit for transition either way?"

I went from C to C++. Does that count? If so, definitely templates - have you seen the error messages? It's like staring at sun:

Error Message wrote:
"std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::ignore(std::streamsize, typename _Traits::int_type) [with _CharT = char, _Traits = std::char_traits<char>]|"

...not informative at all.

Everything else is easy enough.

Whovian wrote:
"I can't wrap my head around is why Sun decided to force everything to be declared in a class."

I don't think it's anything to do with the fact that it's an object-oriented language.

Wazzak
Going from C++ to Java, i was at first like "yay garbage collector! no more explicit destruction!" - which of course only worked til I needed deterministic destruction anyways. Damn.
hanst99 wrote:
til I needed deterministic destruction

Why did you need that?
Destroying OpenGL textures before the context is released.

Destroying OpenGL textures before the context is released.


It is not really much harder than in C++. Just need to provide a manual destroy/close method, similar to C++ destructors. And if you know a little of reflection and the new Java 7 try-with-resources block, you can even accomplish exactly the same behaviour as RAII in C++.
Last edited on
If so, definitely templates - have you seen the error messages?

Try switching to the LLVM compiler with the Clang++ front. The error messages are an order of magnitude more helpful.
It is not really much harder than in C++. Just need to provide a manual destroy/close method, similar to C++ destructors. And if you know a little of reflection and the new Java 7 try-with-resources block, you can even accomplish exactly the same behaviour as RAII in C++.


But that's exactly the problem - I need the order to be deterministic. The context must be released AFTER the textures have been. So you need explicit destruction. Which is what I said (I never said it was problematic to implement in Java, it was just that I came to Java with the expectation that the garbage collector would somehow magically do everything for me).
Last edited on
Going from C++ to Obj-C is a bit meh.

Syntax is funny, straying from dot-notation more often than not. Conceptually, it's a bit similar to Java in some ways, despite being a subset of C.

I thought method calling and definitions were particularly odd.

This call looks pretty funky at first glance. ;-)
[myObject Add: 5 AddTo: 10];
Last edited on
closed account (zb0S216C)
Moschops wrote:
"Try switching to the LLVM compiler with the Clang++ front."

Thanks for the suggestion :) I'll look it up.

Wazzak
I have heard that Obj-C takes stuff from Smalltalk so... this is a block that sends the message Add:AddTo:(5,10) to myObject upon execution?
Yeah, pretty much.

The C++ equivalent would be something along the lines of:

myObject.Add(5,10);

The 'AddTo' part is optional. You can give parameters tags to remind you what they are when you're calling them.

It's weird not using dot-notation. Kind of easy to spot method calls, though, as they'll always be inside of square brackets. There's minor exceptions where Obj-C classes can form their own setter/getter methods and you'd use dot-notation, but that's another story. :-)
Last edited on
It would look like

1
2
3
| myObject |
myObject := MyObjectClass new.
myObject add:5 to:10


in Smalltalk.

Square brackets are used for defining closures in Smalltalk, like

 
1 to: 100 do: [:i | Transcript show: 'Hello World! ',i,'th time!'].


(Squeak/Pharo Smalltalk)
iHutch105 wrote:
despite being a subset of C


I didn't know that! Wow. (EDIT: I mean superset)
Last edited on
Obj-C isn't a subset of C, but I think that was just a slight slip up.
hanst99 is right - Objective-C is not a subset of C, it's a superset of C.
Last edited on
Ah. Sorry, I also typoed that. =P I seem to be prone to typoes.
Last edited on
In fact, the one thing I can't wrap my head around is why Sun decided to force everything to be declared in a class.

It's really no different since you can break encapsulation at will.

I went from C to C++.

I would guess that this is the hardest transition there is. It's particularly tricky because it's a mindset change more than a syntax change. It also leads a lot of developers to thinking that they have successfully moved to C++ when they haven't transitioned at all.


Going from something like Java or Python to C++ would be difficult because of the lack of standardized/built-in libraries to do everything under the sun.
Last edited on
Topic archived. No new replies allowed.