Canol Gökel


Sloganı olmayan blog

Broken a Record

Today, I’ve just broken my old record of writing an errorless program at the first try with 29 lines of code which includes creating classes, subclasses, methods, comments and doing some test 🙂 Hooray Smalltalk! What is your record and in what language? Leave a comment 🙂

Filed under: Programming, ,

Smalltalk and Turkish

I realized one important thing which pulls me towards Smalltalk, subconsciously. Smalltalk’s syntax resembles Turkish in some ways. I will try to show it via examples.

The first thing which seperates Turkish from other English like languages is that verbs are put at the end of sentences, not after the subject. In English, the order of sentence components is:

Subject verb object.

In Turkish:

Subject object verb.

In Turkish, you can join subject and verb into 1 word. In that case it is like:

Object verb.

The key thing here is that objects are “before” the verbs in English and “after” the verbs in Turkish. Let’s take some examples:

1 to: 3 do: [something].

In English like languages you normally tell such a pattern as:

Do something from 1 to 3.

In Turkish:

1'den 3'e kadar birşey yap.

“1’den 3’e kadar” means “1 to 3”. “birşey yap” means “do something”. In Turkish “what to do” is said after specifying other details. But in English you first say what to do and then specify the details.

Take an example for splitting a string. A message might be formed like this:

'A string to be splitted' split.

In english you would say:

Split the sentence "A string to be splitted".

In Turkish:

"Bölünecek cümle" cümlesini böl.

“cümlesini” means “sentence” and “böl” means “split”. In programming we don’t need to specify that it is a sentence because it is understood from single quotes. So let’s form English and Turkish sentences without “the sentence” and “cümlesini”:

In English:

Split "A string to be splitted".

In Turkish:

"Bölünecek cümle" böl.

Can you see the closeness of Smalltalk expression and Turkish sentence?

'A string to be splitted' split.
"A string to be splitted" böl.

Maybe a C++ or Tcl like syntax is more close to English in this one:

split("this sentence");
split "this sentence"
Split "A string to be splitted".

This is because in Turkish, you first tell the object and then what to do with it, in contrast to English inwhich you first tell what to do and then the object in concern.

Now take the ifTrue: controlling message:

[something] ifTrue: [do another thing].

In English you would say:

if something is true do another thing.

It is close but not as close as Turkish because you give the “controlling meaning” before the condition via “if”. In Turkish you give the condition first and then give the controlling meaning:

Birşey doğruysa başka birşey yap.

“Birşey” means “something”, “doğruysa” means “if true” and “başka birşey yap” means “do another thing”.

Birşey => [something]
doğruysa => ifTrue:
başka birşey yap => [do another thing]

The classic C style is more close to English:

if (something is true) do another thing;

We can tell the same thing with whileTrue: message.

In conclusion: Although in some situations C style syntax is more close to English; in general, Smalltalk is more close to both English and Turkish compared to C style syntax. But it is even more close to a Turkish language user. There are “suffixes” in Turkish which causes some serious differences between Turkish and English/Smalltalk but the main order of sentence components causes it to feel native to Turkish people. I read somewhere about Turkish being an ideal computer language syntax but didn’t see an example until Smalltalk. But I think the suffix system of Turkish language would make a computer language design unnecessarily complex, like the article system of German language (der die das) would, too.

Maybe the thing I mentioned above is one of the reasons why I fall in love with Smalltalk syntax.

Filed under: Programming, ,

If you want to understand blocks, then learn Smalltalk

When I was taking a look at Ruby to learn what is it like, I faced a concept called “block”. But I never got it bacause you could do everything with a block, also with traditional methods you learned so far. So I asked myself, why would a human being invent something like block? Maybe this is because of the people who tries to explain the blocks or because of my low IQ but this was the case for me when learning Ruby.

Then I started learning Smalltalk and even before I get to the blocks chapter of Blue Book, I thought there should be some kind of structure to group some expressions so that we can pass them as arguments and so that we can have controlling messages. And Smalltalk showed me the real meaning of the block concept, I got the subject at the first reading.

But if the block concept of Ruby is different then the block concept of Smalltalk and this observation is totally wrong then I would definately like to hear it.

Filed under: Programming, , ,