Saturday, February 25, 2006

Concurrency-Oriented Programming (snooping)

Well, we have heard before that "the free lunch is over".
Here is a post about Erlang as "concurrency-oriented programming".
And here about "Erlang vs Haskell comparison"

If you follow the link, some really interesting quotes appear:

Erlang is the specialist language narrowly focused on networked, highly-scalable concurrent applications.

I love Haskell because it forever twisted my brain into a different shape and I think I'm overall a much better coder now.
Maybe Io could also have some potential for concurrent programming (futures, coroutines, asyncs). Not at the same scale as erlang, but, who knows...

Wednesday, February 08, 2006

New Programming Language (Matz suggestion)

Here are the Obie Fenandez's Notes on the RubyConf 2005.

Matz suggested Io, or Haskell, but also "old" (I would say "classical") programming languages were specified: Lisp, Scheme, Smalltalk.

I've learned Lisp at the University, but I didn't enjoy the prefix notation (+ 2 3 4 5)
Smalltalk is always fun, but it is not a new mind-challenging concept (I would say that ruby is a file-based smalltalk).

Io "is a small, prototype-based programming language. The ideas in Io are mostly inspired by Smalltalk (all values are objects), Self (prototype-based), NewtonScript (differential inheritance), Act1 (actors and futures for concurrency), LISP (code is a runtime inspectable/modifiable tree) and Lua (small, embeddable)."
But for now it is very basic, nearly approaching the 1.0 release. So for more "interesting" stuff,
libraries are missing.

Haskell might be an interesting option. (darcs is written in it). Looking at the introduction,
I saw a qsort implementation, which looks very prolog-like:

Haskell:
qsort []     = []
qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x
where
elts_lt_x = [y | y <- xs, y < x]
elts_greq_x = [y | y <- xs, y >= x]


Ruby:
def qsort(list)
return [] if list.empty?

x, *xs = *list
smaller_than_x, bigger_than_x = xs.partition{|y| y < x}
qsort(smaller_than_x) + [x] + qsort(bigger_than_x)
end

Once again, I was surprized by how flexible ruby is. I didn't know (maybe forgot) about the x, *xs = *list assignement possibility.

ps. here is a japanese post about qsort in several languages.

Saturday, February 04, 2006

Working Effectively With Legacy Code (notes)

Notes from Michael C. Feathers book.

"Code without test is bad code. It doesn't matter how ell written it is; it doesn't matter how pretty or object oriented or well encapsulated it is. With tests, we can change the behaviour of our code quickly and verifiably. Without them, we really don't know if your code is getting better o worse."

...changes in a system: "Edit and Pray", "Cover and Modify"

A Seam is a place where you can alter behaviour in your program without editing in that place. Every seam has an enabling point, a place where you can make the decision to you one behaviour or another.

# Separate the new code (change) from the old code. Contain the change code in:
- a Sprout Method. Can also be static (static methods viewed as staging)
- a Sproud Class. The source Class, cannot be easily tested, so we isolated our change in another class, where we can test it.

- Wrap Method: Rename the old method and make it private/protected. The new method wraps the old functionality with the new functionality.
- Wrap Class: Extract Implementer/Extract Interface.

"Good design is testable, and design that isn't testable is bad."
"When we depend directly on libraries that are out of our control, we are just asking for trouble."

"There is no decent place to sense what this code does."

"Command/query separation: a command should be a query or a command, but not both. A command is a method that can modify the state of the object but that doesn't return a value. A query is a method returns a value but that does not modify the object"

"Programming is the art of doing one thing at a time"
Pair Programming: "It is a remarkably good way to increase quality and spread knowledge around a team"
"Let's face it, working in legacy code is surgery, and doctors never operate alone."