`
winzenghua
  • 浏览: 1355915 次
  • 性别: Icon_minigender_2
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

Is Scala Really the Next C++?

阅读更多

source: http://www.codecommit.com/blog/scala/is-scala-really-the-next-c

5
May
2008

I’ve been turning that question over in my head for a few months now. It’s really a worthy thought. At face value, it’s incredibly derogatory and implicative of an over-bulked, poorly designed language. While I’m sure this is not how the concept was originally intended, it certainly comes across that way.

But the more I think about it, the more I realize that the parallels are uncanny. Consider the situation back in 1983, when C++ first got started. C had become the dominant language for serious developments. It was fast, commonly known and perhaps more importantly, structured. C had successfully applied the concepts shown in Pascal to systems programming, revolutionizing the industry and becoming the lingua franca of developers everywhere.

When C++ arrived, one of its main selling points was as a “better C”. It was possible to interoperate seamlessly between C++ and C, even to the point of compiling most C programs unmodified in C++. But despite its roots, it still managed to introduce a number of features drawn from Smalltalk et al. (such as classes and virtual member functions). It represented a paradigm shift in the way developers represented concepts. In fact, I think it’s safe to say that the popular object-oriented design principles that we all take for granted would never have evolved to this level without the introduction of C++. (yes, I’m aware of Objective-C and other such efforts, but C++ was the one which caught on)

So we’ve got a few catch-phrases here: “better C”, “seamless interop”, “backwards compatibility”, “paradigm shift”, etc. Sound familiar? (actually, it sounds a lot like Groovy) The truth is that Scala seems to occupy a very similar place in history (if six months ago can be considered “history”). Scala is almost an extension to java. It brings to the language things like higher-order functions, type inference and a type system of frightening power. Scala represents a fundamental shift in the concepts and designs we use to model problems. I truly believe that whatever language we’re using in a decade’s time, it will borrow heavily from the concepts introduced in Scala (in the same way that java borrowed from C++).

But if Scala and C++ are so similar in historical inception, shouldn’t we view the language with a certain amount of distrust? We all know what a mess C++ turned out to be, why should Scala be any different? I believe the answer has to do with Scala’s fundamental design principles. Specifically, Scala is not trying to be source-compatible with java. You can’t just take java sources and compile them with Scala.

This clean break with the progenitor language has a number of ramifications. Most importantly, Scala is able to smooth many of the rough edges in java without breaking existing libraries. For example, Scala’s generics are far more consistent than java’s, despite still being implemented using erasure. This snippet, for example, fails to compile:

def doSomething(ls:List) = {
  ...
}

All we have done is omit the generic type parameter. In java, the equivalent would lead to a compiler warning at worst, because java has to remain backwards compatible with code written before the introduction of generics. This “error vs warning” distinction seems a bit trivial at first, but the distinction has massive implications throughout the rest of the type system. Anyone who has ever tried to write a “generified” library in java will know what I mean.

Scala represents a clean break from java. This is in sharp contrast to C++, which was trying to remain fully backward compatible with C sources. This meant inheriting all of C’s weird wrinkles (pass-by-value, no forward referencing, etc). If C++ had just abandoned it’s C legacy, it would have been a much nicer language. Arguably, a language more like java. :-)

Perhaps the most important distinction between Scala and C++ is that Scala is being designed from the ground up with consistency in mind. All of the major problems in C++ can be traced back to inconsistencies in syntax, semantics or both. That’s not to say that the designers of C++ didn’t put a good deal of effort into keeping the language homogenous, but the truth is that they ultimately failed. Now we could argue until the cows come home about why they failed, but whatever the reasons, it’s done and it has given C++ a very bad reputation. Scala on the other hand is being built by a close-knit team of academics who have spent a lifetime thinking about how to properly design a language. I tend to think that they have a better chance of succeeding than the C++ folks did.

So the moral of this long and rambling post is that you shouldn’t be wary of the Scala language. It’s not going to become the next evil emperor of the language world. Far from it, Scala may just represent the next step forward into true programmatic enlightenment.

<!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"> <rdf:Description rdf:about="http://www.codecommit.com/blog/scala/is-scala-really-the-next-c" dc:identifier="http://www.codecommit.com/blog/scala/is-scala-really-the-next-c" dc:title="Is Scala Really the Next C++?" trackback:ping="http://www.codecommit.com/blog/scala/is-scala-really-the-next-c/trackback" /> </rdf:RDF> -->
分享到:
评论

相关推荐

    scala for the impatient(2017,完全清晰打印版,无水印)

    The evolution of traditional languages such as Java, C#, and C++ has slowed down considerably, and programmers who are eager to use more modern lan- guage features are looking elsewhere. Scala is an ...

    Scala for the Impatient 完整版带书签

    ### Scala for the Impatient:快速学习Scala的指南 #### 一、书籍简介 《Scala for the Impatient》是一本由Cay S. Horstmann所著的关于Scala编程语言的入门书籍,它被誉为是快速学习Scala的最佳选择之一,并且...

    经典书籍 Scala for the Impatient.pdf

    ### 经典书籍《Scala for the Impatient》知识点解析 #### 一、书籍概述 《Scala for the Impatient》是一本旨在帮助读者快速掌握Scala语言的实用书籍。本书由Cay S. Horstmann撰写,他是一位知名的计算机科学教授...

    scala for the impatient

    Scala is a modern programming language for the Java Virtual Machine (JVM) that combines the best features of object-oriented and functional programming languages. Using Scala, you can write programs ...

    Scala for the Impatient

    本书《Scala for the Impatient》是为那些对快速学习Scala编程感兴趣但又不愿意阅读长篇大论的读者所写的。作者Cay S. Horstmann假设读者已经有了Java、C#或C++等语言的编程背景,因此不会在变量、循环或类等基础...

    Scala-in-Action.pdf

    Scala is a feature-rich language and it is not possible to cover all of its features in one book, at least one of a reasonable size. For that reason, I deliberately avoided some of the more advanced ...

    Scala for the Impatient(2nd) azw3

    Scala for the Impatient(2nd) 英文azw3 第2版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    scala for the impatient 完整版

    SCALA,高开发,函数式编程,无逢结合JAVA库。下一代JAVA,你的首选! 不管是scalding, spark,SCALA无处不在。 完事版,不差页,很难找的哦! 资源多多的有,差分就传点了^_^

    Scala for the Impatient(2nd) epub

    Scala for the Impatient(2nd) 英文epub 第2版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    Scala for the Impatient(2nd) 无水印pdf

    Scala for the Impatient(2nd) 英文无水印pdf 第2版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系...

    scala for the impatient 第1到9章

    本书《Scala for the Impatient》通过对Scala特性的讲解,为读者铺平了通往现代编程技术的道路,无论是对于希望超越Java或C++的程序员,还是那些希望快速掌握一门新语言的读者来说,Scala无疑是一个非常有吸引力的...

    Programming in Scala

    Programming in Scala is the definitive book on Scala, the new language for the Java Platform that blends object-oriented and functional programming concepts into a unique and powerful tool for ...

    为Java虚拟机编译Scala(Michel Schinz)Compiling Scala for the Java Virtual Machine (Michel Schinz)

    Scala是一门高级编程语言,支持面向对象和函数式编程。它的设计宗旨是在保持表达能力的同时,能够与Java平台上的现有库无缝集成,因此能够在Java虚拟机(JVM)上运行。编译Scala代码到JVM的上下文是一个复杂的过程,...

    Scala for the Impatient.pdf

    The provided excerpt from "Scala for the Impatient" introduces several core concepts in the Scala programming language, which is known for its functional and object-oriented features. Below, we will ...

    Scala.for.the.Impatient.2nd.Edition

    《Scala for the Impatient》第二版是一本针对初学者的Scala编程语言教程,以其简洁明快的风格和实战导向的教学方法而备受推崇。本书旨在帮助读者迅速掌握Scala的基础知识,并深入理解其高级特性,以便在实际开发中...

Global site tag (gtag.js) - Google Analytics