Scala

Scala patterns (#3) - Successor Value

其实这个设计模式也不是Scala语言特有的,只是因为在Scala in action(下文中提到的书都是指本书)中提到,因此做一个小结。在书的第五章Functional Programming中讨论函数式编程的时候,谈到了纯函数式编程、面向对象编程和非纯函数式编程的一些特点。Scala是一门杂糅的编程语言,它不是纯函数式语言,这样就涉及到一个问题:如何尽量多地使用它的函数式特性,同时避免或者减少对于对象状态的改变。作者在这时举了一个小例子,就是Successor Value模式(书中也叫Functional Object模式,但是没有查到相关资料)。

Functional programming matters

During the reading of Scala in action, I found the reference link quoted by the author(Nilanjan Raychaudhuri), which is an introductionary article about functional programming. I’ve learned that functional programming is minority compared to object oriented programming, which means it is not popular, but being a curious programmer, I am eager to know for a long time why it has its attractiveness, where it is being used and how it can be used to solve real world problems.

Scala Patterns(#2) - Lazy initialization

延迟初始化

延迟初始化是程序设计中减少开销、提高性能的一种做法,同时它也是创建型设计模式中的一种。在Effective Java里,Bloch是这么描述延迟初始化的,

Lazy initialization is the act of delaying the initialization of a field until its
value is needed. If the value is never needed, the field is never initialized.

Scala patterns (#1) - Option

自从1994年《设计模式:可复用面向对象软件的基础》问世以来,设计模式就备受关注,虽然业界褒贬不一,而且有人专门写了反模式来陈述其弊端,但大家对它的作用大部分还是认可的,尤其是在面向对象编程领域。但是,正如Brooks所说的“天下没有免费的银弹”,软件的本质问题是管理复杂度,所以能用设计模式解决问题,它必然也会带来衍生问题,工具都有利弊,如何更好地使用工具才是王道。为了减少对设计模式的滥用和简化设计(既然可复用,为什么不直接让语言天生支持呢?),多年以来,人们一直期望在语言层面增加对可复用编程模式(pattern/paradigm)的支持,而这些想法确实也逐渐被多种现代编程语言所采纳。

lambda and closure

lambda又称为lambda表达式lambda演算子,名字听起来挺高端,其实在编程语言里倒也不难理解。但是,和lamba相比闭包却没那么直观。这两个概念作为函数式编程基础的一部分,是必须要掌握的。另外,Java 8也引入了lambda表达式,C#也从版本3.0后开始支持lambda,可见这些函数式编程的特性已经逐渐被主流的面向对象语言所借鉴吸收。

Scala levels

Martin曾于2010年在Scala讨论组内参与过一个讨论,并在最后总结了Scala语言的水平等级,发表在Scala语言官网上(原文地址1,目的是为Scala语言初学者和爱好者提供参考。在前面的博文Scala for the impatient中书的作者也提到过,基本上分为应用开发和库开发两个大类,而每个大类可以细分成三个等级,以下为相关原文的翻译2

Scala中的面向对象编程

前几天看到一篇有关Scala的文章,其中对它的发展有些担心:Scala会不会成为下一个C++?这种担心也并非毫无道理,看完Scala in action的第三章,我的感觉是Scala确实强大,但也增加了一些不必要的特性,或者换句话说,有些特性是一般应用开发者不需要关心的,只有库开发者才有必要掌握。所以,在适当的时候,我需要把Martin的Scala开发水平等级和Twitter的Effective Scala再好好研究一下,以免过早被一些高级的语法细节纠缠却忽视了实用性强的基本特性。

第三章OOP in Scala中介绍了Scala面向对象编程方面的一些基本概念,这些概念或者说语法元素有的是和Java类似的,有的是全新的,所以有必要简单总结一下再继续阅读。

REST client scala script

This post is written in English, because I read one article recently that says English is one of the key (programming) languages you need to master. I cannot agree more, :). English is very important for progammers, especially if you want to be a top programmer in specific area. There are much more great resources in English than in other languages, so why not start to write some posts or articles in English and make yourself comfortable with reading, writing and thinking? I appologize for any readers of this blog who do not master English well, but I have to do it for me and for you, because anyhow we need improve ourselves up to the next level and it’s almost impossible without English. Get used to it and you’ll be happy with it soon.