Try these 4 languages from 4 corners of Programming

栏目: IT技术 · 发布时间: 3年前

Try these 4 languages from 4 corners of Programming

Try these 4 languages from 4 corners of Programming

# c # haskell # clojure # smalltalk

Try these 4 languages from 4 corners of Programming ・3 min read

There are thousands of programming languages, all having features unique than others. There are some more readable, others more performant, some are simple, others are complex. Here I'm presenting you 4 different programming languages from 4 different sides of programming. I invite you to try each of them, enjoy their strengths, find their weaknesses. Each one of them is very different than the others. They each are better for some kinds of problems. They will teach you the same problem in different ways.

1. C

While working on the Unix operating system at Bells Lab, Dennis Ritchie wanted a language that will suit the task of writing parts of the Operating System. He wrote C language taking inspiration from BCPL and B.

A lot of C's syntax maps directly to machine code. C has the power of assembly but unlike assembly, it is cross-platform, If you wrote your code with portability in mind then it can work on multiple OSes and CPU architecture without much code changes.

When you want to talk directly to the machine, removing all the abstractions in between you and the machine, then C is the language for that kind of tasks.

Here is some C code

int square (int number) {
    return number * number;
}

and here it the assembly code generated by the compiler

square(int):
        push    rbp
        mov     rbp, rsp
        mov     DWORD PTR [rbp-4], edi
        mov     eax, DWORD PTR [rbp-4]
        imul    eax, eax
        pop     rbp
        ret

2. Smalltalk

When I made up the term object-oriented, and I can tell you I did not have C++ in mind.  -- Alan Kay 

Smalltalk was created to teach kids programming. Creator Alan Kay had revolutionary ideas about how programming should be done. He pioneered the idea of individual units communicating through message passing. He believed that languages should be built around a generalized concept. Smalltalk and Object Oriented Programming revolutionized the world of programming but certainly not a good way, the world misunderstood the whole idea of Object Oriented Programming. Classes became the epic center of Object Oriented Programming.

here is some smalltalk code:

"Return the weekday of a date"
'2013/5/7' asDate dayOfWeekName

"Save the HTML source of a web page to a file"
'http://www.pharo.org' asUrl saveContentsToFile: 'page.html'

"Count the number of, or show the leap years between two years"
(1914 to: 1945) count: [ :each | Year isLeapYear: each ].
(1895 to: 1915) select: [ :each | Year isLeapYear: each ].

If you already know ruby, smalltalk will not take a lot of time to grasp, but its live debugger is something from another world.

3. Lisp

“Lisp is a programmable programming language.”  — John Foderaro, CACM, September 1991

If you are looking for a language in functional programming world, there is a good chance you will hear about lisp. Lisp is a minimalist kind of programming language. Its has virtually no syntax. Lisp is one of those languages which is enlightening. Currently the most popular lisp variant is Clojure .

Lisp is programmable. which means if you don't like any constructs of of the language, you can override it with what works better for your team. Imagine if javascript was lisp we could fix a lot of its bad parts.

here is some clojure code:

;; define a var
(def a 42)
;; => #'user/a

;; call a function named `+`
(+ a 8)
;; => 50

;; call a function named `even?`
(even? a)
;; => true

;; define a function that returns the remainder of `n` when divided by 10
(defn foo [n] (rem n 10))
;; => #'user/foo

;; call the function
(foo a)
;; => 2

;; if else 
(str "2 is " (if (even? 2) "even" "odd"))

4. Haskell

Haskell is the language grown out of mathematics world, It is a statically typed (perhaps the best kind of static typing), functional programming language. Unlike most mainstream static typed languages it has strong type inference so you don't have to write types everywhere but you still get type safety.

If you are writing in statically typed language, you should try Haskell, it has very strong type inference. You can see the below code which has type safety but I didn't wrote any types.

Haskell has pattern matching, recursion, list comprehension, first class functions and all the other cool stuff of functional programming languages.

-- Using recursion (with the "if then else" expression)
factorial n = if n < 2
              then 1
              else n * factorial (n - 1)

cover image credits: Thanks to Ian Schneider for sharing their work on Unsplash


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

C++沉思录

C++沉思录

Andrew Koenig、Barbara Moo / 黄晓春、孟岩(审校) / 人民邮电出版社 / 2008-1 / 55.00元

《C++沉思录》基于作者在知名技术杂志发表的技术文章、世界各地发表的演讲以及斯坦福大学的课程讲义整理、写作而成,融聚了作者10多年C++程序生涯的真知灼见。全书分为6篇32章,分别对C++语言的历史和特点、类和继承、STL与泛型编程、库的设计等几大技术话题进行了详细而深入的讨论,细微之处几乎涵盖了C++所有的设计思想和技术细节。全书通过精心挑选的实例,向读者传达先进的程序设计的方法和理念。一起来看看 《C++沉思录》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

SHA 加密
SHA 加密

SHA 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器