Tag Archives: Programing Language

Why not ruby replace the Block with lambda?

Where there is a will, there is a way. Some times when you are programming in C# or python, you may think about is there a way to break out of a function block to it’s parent scope?

We learned that in C we could use goto to jump around the codes. That’s a great tool when you need to jump out of deep nested loops. But you can’t jump out of a function with this tricky tool. If you learned about POSIX C, the longjump can meet the need, though it’s intended to easier the complexity in error handling. Requirement like jumping out of a function is really rare when coding. We always can find out a solution. Such as try catch in C++ or C#.

Lua code fragment below, you can’t stop the code from going through all the numbers. The permutation is a system predefined function, and we cannot modify it.

But Ruby can complete the task with Block like below:

The differences make the existence of things reasonable.

创建新的语言

由于人的月历和知识的有限性,性能和开发效率的矛盾,一门语言的发明者不可能满足所有程序员的要求。随着高级语言的普及,那些不满于现状的程序员们会越来越多的选择定制自己的语言,当然我这里不是说想Lisp那么干,而是真正的从语言特性上定制。

说到这里,就不得不提及语言特性优劣该如何量化问题。简单的说就是我们该怎么判断一门语言的某个特性是优秀的还是表现一般呢?对于主观性很强的问题往往难以量化。我个人的量化标准是它对实际问题的抽象程度,抽象度越高越慢、越高级、越智能、开发效率越高。

比如C语言的for循环,相较于汇编的jump或者loop,抽象程度更低,它封装了更加抽象的循环过程——人们日常计数的行为过程:起始点,终点,步长,每次计数后干点什么。功能都可做到一致,但是表达方式的变化对于人们的理解有很大的影响。

这里出现了人们的日常行为,我觉得很重要,如何将底层的操作抽象成人们熟悉的日常操作行为是语言设计的重要问题。

另一个问题是如何将智能引入到语言本身,比如类似Object-C的智能垃圾回收,这个我觉得将是下代高级语言的发展方向。

Continue reading