- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Is Scala the Next C++
I have recently seen a number of discussions around issues like "is
Scala too complex, "is Scala too hard to learn," "Thinking in a
language vs. thinking into a language." etc.
I find these discussions fascinating as I often find myself on both
sides of the fence. At times I find coding in Scala increasingly
seductive and satisfying, at other times I try to read some of the
advanced code and concepts I see people discussing and I feel like a
moron who has no hope to ever grok what they mean, let alone simply
understand it. Often I just have to be satisfied that I get the gist
of it.
This sort of reminds me of my experience with C++. I started trying
the language as soon as there were competent compilers available and
enjoyed the new learning experience, trying to sample as many new
language features as I could and was generally able to master most of
them. However, after a while I was not writing code as often and ever
time I tried to start some new little project I found the start-up
cost of having to relearn C++ too high and switched back to C as much
as possible. My experience was that unless I used C++ continuously,
the overhead of coding was too high.
Eventually I took a class from Scott Meyers. My takeaway point from
that class was that there were programmers and there were type
designers. Type designers had to be very very good at type design. On
the other hand, with well designed type libraries and APIs, being a C+
+ programmers was not so bad after all.
After a while I did not do much C++ because I moved on to Objective-C
because I drank of the NeXT Cool-Aid. I really took to Objective-C
because it was was so much more simple to think in that language than C
++, and the NeXT types and APIs were awesome.
Eventually I moved on to Java and almost immediately became addicted
to the simplicity (over C++) and power (close to C++), but mostly to
the garbage collection. There was a reason I used to love writing code
in LISP.
Eventually I had a job where I had to look at some C++ code again, but
by then it was Microsoft C++ with ATL/COM. My first reaction was WTF?
How did this language get so messed up? Fortunately I was senior
enough I could just say "no way I am touching that!"
Eventually Java became my de facto language and I became increasingly
proficient with it. Then I started looking at Groovy and really liked
how much more expressive Groovy was, with minimal added complexity. I
found it hard to do much with Groovy because I could not convince my
colleagues of its value. Then I found Scala and tried to learn it but
had to bail because it was too confusing. But Scala is seductive!
Eventually I found my way back and became relatively proficient with
it. Yes, I can even write in a functional style and comprehend the
value of it. But I still cannot convince my colleagues of its value
either.
Martin Odersky's Levels http://www.scala-lang.org/node/8610 reminds me
very much of what I learned from Scott Meyers - that you do not need
to grok all of Scala to be proficient and productive in using it. I
personally hope to be able to transition some day from Java to Scala
as my main working language, but at the same time I am mindful of what
became of C++ because the geniuses who came up with ATL and COM.
What I am hoping we might debate is: what is to prevent Scala from
going the route of C++ (and maybe other trials and tribulations of
learning and using Scala). What are the barriers to adopting Scala,
and what compelling advantages does Scala offer to seduce us past
those barriers. Every week I see more barriers coming down because the
keepers of Scala work hard to remove them, but almost as often I see
people pointing out new barriers. Has Scala reached critical mass, or
are we still waiting for it?
Cheers, Eric










Re: Is Scala the Next C++
On Tue, Sep 6, 2011 at 2:25 PM, Seth Tisue wrote:
> read and write. Whereas even the best C++ code is... C++. As you say,
> "Scala is seductive." C++ is not. I suggest you tune out the FUD and
> trust in the pleasure you've experienced writing Scala.
i do not even remotely like C++, but i have nevertheless always been
impressed with examples by Bjarne Stroustrup to be clean and concise
and impressive. have a sort of reality distortion field effect where
i'm like "oh hey maybe i can get to like c++ after all" but then i end
up seeing how the *world* not just Bjarne use it. i suspect the same
is true, even if less so, for most all programming languages. the more
complexity is available, the more it will be used and guaranteed
abused. while you can try to avoid it, it means you have to grok which
advanced use is good vs. bad which means you have to grok the
complexity.
sincerely.
Re: Is Scala the Next C++
On Tue, Sep 6, 2011 at 1:45 PM, Eric Kolotyluk wrote:
> Martin Odersky's Levels http://www.scala-lang.org/node/8610 reminds me
> very much of what I learned from Scott Meyers - that you do not need
> to grok all of Scala to be proficient and productive in using it.
<$0.02 rant>personally i think that's total bull. people say the same
thing about java generics and other stuff, but inevitably even a
regular Joe will end up trying to use some library that ends up having
some issue behind the curtain that is some fubar advanced thing and
they are in a world of suck until either it gets fixed or they learn
about the advanced thing and fix it themselves or they get some cargo
cult help or whatever. if there is complexity in the language *then
there is complexity in the language*.
sincerely.
Re: Is Scala the Next C++
On Tue, Sep 6, 2011 at 10:48 PM, Raoul Duke <raould [at] gmail [dot] com> wrote:
I don't agree. Your point does hold for Java generics, and that's why I have argued against wildcards from the start: wildcards shift complexity from the library designer to the library user. Your argument is empirically not true for Scala collections. They are about as complicated as you can get from an implementation point of view, yet they are widely acknowledled to be very nice to use. So Scala collections are a counter-example to your argument.
-- Martin
--
Martin Odersky
Prof., EPFL and Chairman, Typesafe
PSED, 1015 Lausanne, Switzerland
Tel. EPFL: +41 21 693 6863
Tel. Typesafe: +41 21 691 4967
Re: Is Scala the Next C++
On Tue, Sep 6, 2011 at 10:55 PM, martin odersky wrote:
>
>
> On Tue, Sep 6, 2011 at 10:48 PM, Raoul Duke wrote:
>>
>> On Tue, Sep 6, 2011 at 1:45 PM, Eric Kolotyluk
>> wrote:
>> > Martin Odersky's Levels http://www.scala-lang.org/node/8610 reminds me
>> > very much of what I learned from Scott Meyers - that you do not need
>> > to grok all of Scala to be proficient and productive in using it.
>>
>> <$0.02 rant>personally i think that's total bull. people say the same
>> thing about java generics and other stuff, but inevitably even a
>> regular Joe will end up trying to use some library that ends up having
>> some issue behind the curtain that is some fubar advanced thing and
>> they are in a world of suck until either it gets fixed or they learn
>> about the advanced thing and fix it themselves or they get some cargo
>> cult help or whatever. if there is complexity in the language *then
>> there is complexity in the language*.
>>
>> sincerely.
>
> I don't agree. Your point does hold for Java generics, and that's why I have
> argued against wildcards from the start: wildcards shift complexity from the
> library designer to the library user. Your argument is empirically not true
> for Scala collections. They are about as complicated as you can get from an
> implementation point of view, yet they are widely acknowledled to be very
> nice to use. So Scala collections are a counter-example to your argument.
>
long rant follows, but hopefully good bits in between....
I'd actually say they are the perfect example, although probably not a
"world of suck". When using at the [use case] level everything is
great, but there are plenty of gotchas.
Whilst writing Scales Xml, I quickly found CBF's aren't hidden from
the developer, but will "infect" any code that attempts to be generic
with a container. The infection is actually of course a very good
thing in the medium to long term, you want your libraries to be
flexible as to container, cbfs are a great way to get that, there is a
bit of annoying boiler plate to go with it though.
But if your code forgets to pass an implicit one along, and its
something the compiler seems to grok, you end up with classType and
wrappedRefArrays and other things semi silently stealing your
performance away. Your tests will work, it will all seem good, but
there is this little tight loop performance killer lurking around.
I've since started using yourkit even just to look for this happening
(with jad to check).
After initial pains I could swap out IndexedSeqs with ease to allow
profiling different core collection choices for Scales Xml, my only
remaining grief was the inability to directly re-use parts of Vector
and the hidden (but obvious when you think of it) cost of flatMap'ing
a List (especially when you don't care about the order of the
results).
But simply put, in order to coerce the collections to my whims, I
spent a lot of time digging in the library source and asking the list
for help as well (which were, as usual, stellar).
Having said that, as a direct result of the collection apis design,
and indeed the whole cbf implicit passing, I have been able to produce
great results that I'm very happy with and see that time spent as
clear investment.
To answer the OP though, I relished the crazyness in C++ land,
typename this, curiously recurse that, algorithm + functors, raii ftw
and fc++ as the poster child for how it could be, and also why it
probably shouldn't be. For me Scala is like returning to that
flexibility and power but with a nice warm blanket and better tooling
around it plus even more depth for when I need it. Java is only as
easy as its ioc, ejb, classloader mess lets it be.
Perhaps Scala lets you get caught up in the language snags a bit more,
but its so rich and the compiler and tools are so helpful that I'm
soon spending more time solving problems then fighting the language.
I day to day in Java (with small occasional bursts of Scala), and
can't wait to get back into a language that lets me express my
solutions more clearly.
There are simply a lot of people for whom learning something like
Scala won't be interesting, they have a 9-5 with tooling that does
enough to get them paid. That doesn't imply one is a l33t haxor for
knowing/using Scala (one can write junk in any language), just that
people can have other priorities. I don't buy the whole some
developers just can't learn Scala argument but I have a lot of
sympathy for the question of interest, if you don't want to learn
you'll struggle with most things. If you don't have the time to learn
in depth you'll also likely suffer, its just normal, time lets you
make the mistakes you need to make to learn.
I see a lot of truth about large corporations rewarding choices of
tools/languages on a "how cheap can we get them" basis, and that
applies to developers skills/knowledge as well. That's just one
incredibly hard marketing and mindshare battle that takes many, many
years to adjust.
Re: Is Scala the Next C++
On Tue, Sep 6, 2011 at 1:55 PM, martin odersky <martin [dot] odersky [at] epfl [dot] ch> wrote:
My experience with Java Generics is that I have hurt my brain on several occasions trying to grok wildcards. In practice I have never run into a serious problem I could not solve, and many times the Eclipse IDE has lead me to the solution.
I really understand the mess created in Java trying to shoe-horn generics in after the fact, and all the controversy - but my reality is that I have never had to swear out loud solving a problem with Java generics. The fact that generics work so much better in Scala than Java is just gravy.
What I struggle with these days is trying to understand things like Continuations. For example, as a UI designer I sense their value in possibly being able to eliminate some of the boilerplate around concurrency (i.e. SwingWorker) and callbacks (i.e. EventListeners), but I cannot yet reason it out. My hope is that someday someone with 20 more IQ points than me will write an 'elegant UI API' that incorporates Continuations and I won't really have to really understand them too deeply. On the other had if there are bugs in that 'elegant UI API' I am afraid I might not be able to work around them and may get blocked at an inconvenient time.
Cheers, Eric
Re: Is Scala the Next C++
hi,
On Tue, Sep 6, 2011 at 1:55 PM, martin odersky wrote:
> I don't agree. Your point does hold for Java generics, and that's why I have
> argued against wildcards from the start: wildcards shift complexity from the
> library designer to the library user. Your argument is empirically not true
> for Scala collections. They are about as complicated as you can get from an
> implementation point of view, yet they are widely acknowledled to be very
> nice to use. So Scala collections are a counter-example to your argument.
i appreciate that you in general claim to try to worry about things
being overly complex and confusing, and have made efforts to avoid
that.
in my personal use of the collections, which was most recently like 6
months ago, i recall being frustrated with them at times; perhaps it
was just my newness to scala and the documentation and the general
sugar available at times. actually i think a lot of it might be the
syntax sugar. well, that and the various scala syntax conventions.
there are the real issues of how the collections have used inheritance
choices which only work for some but not all use cases, etc.
anyway, even if collections happened to be a perfect little world of
perfect usability for all types of users, the questions that get
posted on the lists make it pretty clear to me that Scala has enough
things that feel like corners to make it feel more akin to C++'s
seemingly arbitrary complexity than Java's painfully over-verbose but
for the most part stupid simple obviousness. scala might actually even
be doing a great job of following some core principles, but they end
up with things like the val 1 = 2 usability silliness.
now, nobody is being forced to use Scala, i'm not even saying it has
to change; there are obviously plenty of people loving it.
i'm just saying that i find it patently silly for people to claim that
the complexities (or powers, whatever you want to brand it as :-) of
Scala will never impact a Regular Joe Newbie Low-Brow Programmer.
(probably a lot of my view is because i am not immersed in it, which i
take to mean i am not inured to the sometimes from my personal
usability viewpoint crazy stuff.)
sincerely.
Re: Is Scala the Next C++
On Tue, Sep 6, 2011 at 2:17 PM, Raoul Duke <raould [at] gmail [dot] com> wrote:
My personal attitude is that I am wary of the scary stuff in Scala, but still confident to use Scala. There are trade-offs between power and complexity, so you have to find ways to mitigate things. Each software developer has to make a personal judgement of what tools they are confident to competent to use. I am confident and competent to drive a car, but neither confident nor competent to fix the engine if there is a serious problem.
For example, I have had little trouble using Actors in Scala, because I have used languages like SR before, and because Actors in Scala are well sugared. I know there is more lurking behind the scenes with Actors, but I have to trust that the people who implemented the Actors API and sugar were competent, and enough people have used Actors to tease out any bugs.
Cheers, Eric