Why you should learn C and not Scala
Jimmy: Hey, I started to learn JAVA, the object oriented programming languague. I’d like to become a programmer
Me: very good Jimmy
Jimmy: But I am a bit confused.
Me: Why ?
Jimmy: for example, Java Strings can be split but I cannot join them back from an array like. anArray.join(” “)
Me: Well Jimmy this is not implemented, but you can use google collections library and write Splitter.on(’,').split(”foo,bar”) or String s = Joiner.on(”, “).join(numbers);
Jimmy: Wow this is cool
Me: Yes isn’t it ?
Jimmy: But those Joiner and Splitter classes and their methods are static ? Why do we use static methods here, I thought we use objects and their methods and not static helpers. they’r like functions I know from C.
Me: Yes.
Jimmy: I have a great Idea, I’ve learned about those subclasses; we could implement a subclass from java.lang.String or java.lang.Array and implement join and split.
Me: No you can’t, they’r final classes
Jimmy: Ouch… yes and I’ve learned we could’t change final classes.
Me: Yes, Jimmy right. Think you’ve got points on your exam for that
Jimmy: Since we use all these functions, should I learn C now ?
Me: No, Jimmy.
Jimmy: I started to read a great book. It advises me to use those Generics thing with collections like List or Maps.
Me: Great Jimmy, Generics is new stuff introduced with Java 5.
Jimmy: But Java 5 is already End Of Life
Me: Yes Jimmy, but Generics are still some kind of new.
Jimmy: Yeah, I’ve heard its so cool to use Generics and I’ve read I should use Generics in all my new code.
Me: Great Jimmy, you’r a fast learner.
Jimmy: I’m a bit confused.
Me: Why ?
Jimmy: I was not able to declare a map like this: Map<String, int>
Me: Well Jimmy, you can’t put a primitive type into a Generic Map. You only can put objects into it. Use Map<String, Integer> instead.
Jimmy: But I’ve read in the great book, that I should avoid Boxed Primitive Types and those Integer and Long types are new since Java 5
Me: Yes, but you have to use them with Generics like your example; otherwise don’t use them as advised, they have a few side effects.
Jimmy: Ah I see, I should not use Objects but primitive types.
Me: Sometimes yes, Jimmy, sometimes no.
Jimmy: Ok, hey I’ve got a bit to feel like an expert now.
Me: You’ll pass your JCP exam for sure.
Jimmy: Yeah, Java is a great language. Things like threading are so easy, just place synchronized in front of a method and I’m safe.
Me: Not exactly.
Jimmy: Why ? “Threading is implemented right into the languague (TM)”
Me: You souldn’t use threads in Swing or JEE.
Jimmy: Not ? Well JEE comes after my JCP exam, then I wan’t to become a Developer and then a Business Component Developer.
Me: Great Jimmy, great.
Jimmy: But if I can’t use threads in JEE or objects and subclasses why should I learn that now ?
Me: Scaling up business applications in JEE is a container thing; the container knows better how to scale your application.
Jimmy: Yes, I’ve heard from those big scaleable application containers. Threading, Transactions, Clustering… ALL built in.
Me: Yes, big business.
Jimmy: and User Interfaces like Swing ?
Me: Well with Swing you can use SwingUtilities.invokerLater and pass a Runnable to it.
Jimmy: I see. So I use one of those static methods to make my User Interface like a single threaded application ?
Me: Yes Jimmy, Swing is not multithreaded.
Jimmy: I see, like Adobes Flex and ActionScript3 ? They use a single threaded VM I’ve heard.
Me: Yes Jimmy.
Jimmy: And JavaScript, they also have Single Threaded VMs. So why the synchronized keyword and what should we do with all the Multicore CPU’s we’ve around ?
Me: Well Jimmy, the Compiler knows better how to deal with your CPU cores.
Jimmy: Like the containers in JEE ?
Me: Yes, like that.
Jimmy: Yeah like google. So google uses JEE to scale their applications like GMail up to their millions of happy users ?
Me: No. They built their own system.
Jimmy: Like GWT ?
Me: yes.
Jimmy: Its JavaScript ?
Me: Yeah, Java compiled to JavaScript.
Jimmy: Cool. I’ve heard they also compile JAVA code to bytecode and then transform them to the Dalvik VM.
Me: Yes, Dalvik is a VM for mobile devices.
Jimmy: Why don’t they use JavaME ? Mobile Edition, its made for mobile devices.
Me: Dalvik performs better and reduces bytecode size.
Jimmy: Cool. Iv’e heard about all those Script languagues recently. Is JavaScript a successor of Java then ?
Me: No.
Jimmy: But, JavaScript has things like function objects, the same as ActionScript3 has.
Me: Yeah. Nice to use.
Jimmy: The same as code blocks ?
Me: Yea, but they are called Closures.
Jimmy: They’r cool. Since Java 5 is not anymore so new, Java 6 is here and JDK 7 is comming soon, does JDK7 have function objects or closures ?
Me: No.
Jimmy: And array Joiners ?
Me: No.
Jimmy: But where is innovation then ?
Me: Jimmy, you should open your view and see the Big-Picture.
Jimmy: Ah… you mean backward compatibility ?
Me: Yes, Jimmy. Great, u’r a fast learner. I think you can skip the Developer and go right to System Architect.
Jimmy: Thanks
I was always quick in gaining things.
Me: Nice, Jimmy.
Jimmy: So, with all those millions of Java Users, and trillions of lines of JAVA code; we can’t introduce things like closures, blocks, symbols and properties ?
Me: You mean symbols like in Ruby ?
Jimmy: Yes, I’ve done a Website for my sister in Ruby on Rails. Symbols are way cool.
Me: Ah I see.
Jimmy: Yeah Ruby, but none of my friends know about this Ruby thing.
Me: Its an old and quite mature languague now.
Jimmy: Yeah, like Smalltalk ?
Me: Yes.
Jimmy: It looks so strange to me ?
Me: Why.
Jimmy: Well, I miss all those braces and it has curious keywords.
Me: Well its different.
Jimmy: Like scala ?
Me: Yes. Like scala and like Smalltalk.
Jimmy: Smalltalk, I’ve heard about. It also has a VM.
Me: It had.
Jimmy: And evereything is an object.
Me: It was.
Jimmy: And it had a big memory footprint.
Me: Yes it had.
Jimmy: Like Java ?
Me: Yes, somehow like Java.
Jimmy: Does Any1 use Smalltalk these days ?
Me: No.
Jimmy: Buts its pure OO.
Me: Yes, we don’t use it, because its too strange and doesn’t look like C.
Jimmy: Ah, I see not like C. Same as Scala doesn’t ?
Me: Yes.
Jimmy: Yeah, yesterday I saw this piece of code from ScalaTest.org:
"A Stack" should "pop values in last-in-first-out order" in { val stack = new Stack[Int] stack.push(1) stack.push(2) stack.pop() should equal (2) stack.pop() should equal (1) }
Me: Aha.
Jimmy: I was surprised and irritated when to use, for example, the word Stack in a String or not. Or “in” in a String or not.
Me: Yes, the code looks like beautiful.
Jimmy: But how should I refactor this ?
Me: Well Jimmy I have to go now… since you’r a fast learner you’l catch that too.
[...] This post was mentioned on Twitter by marcellanz, majson. majson said: lmao http://marcellanz.com/?p=24
#java #funny [...]
Great read! Thanks!
Nice one, Marcel. Keep it up.
good ironic post (in the actual sense and Socratic sense)
It worth knowing the languages most asked for in job descriptions in your area. It is also worth doing something you find fun and interesting too.
Jobs on jobserve. sql: 4872, C: 3740, Java: 3142, C#: 2161, C++: 1818, Ruby: 192, Cobol: 108, Fortran: 41, Groovy: 20, Scala: 7.
Earning over £75K/y: C: 689, Java: 656, Sql: 646, C++: 487, C#, 432, Ruby: 74, groovy: 10, fortran: 8, cobol: 2, scala: 1
I find it interesting that certain languages tend to pay more proportionally. On proprortion, ruby would be a better choice. After, all the port popular languages.