Canol Gökel

Icon

Sloganı olmayan blog

Choose the next language for iyzi Forum

Details are here: http://ubuntuforums.org/showthread.php?t=1072542

Filed under: Programming,

Variable variable names; PHP and others…

As you might know, in PHP you can easily use a variable to name another variable. For example,

$example = "canol";

Now, we will create a variable named “canol” with value “gokel”:

$$example = "gokel";

This is a really useful feature. But the community of other languages just can’t seem to accept it. Ask them how to use variables variable names and they will answer: “Use hashes, using variable variable names is stupid”. There are even some articles about it being stupid: http://perl.plover.com/varvarname.html

Although in the case of given examples in the link I’ve given above it is true, this is not the case always. I’ll give you a simple idea of a program and tell me how to do this using hash tables.

Suppose we have program, which asks user to enter a variable name, and the program looks whether that variable is defined in itself, then prints its value if it is defined. Can you write this program without using variable variable names? Well, if you consider writing an hash table which will include all the variable names you use and updating it whenever you change your program “not being stupid”, then, yes you can…

Filed under: Programming, , , , ,

XML: <!-- Weirdly --> Extensible Markup Language

I was looking at XML these days. It is really interesting language. It is very useful and I like it a lot and I used it in some of my projects to save data but as I learn how I can extend it or use the not well known features, it confuses me.

For example, you can create entities, which are like variables in other languages. You can define/declare entities like this:

<!ENTITY client "Canol">

Here, we created an entity named client and which has a value of Canol. The thing I cannot understand is that why we use such a not understandable syntax. It is against to the intention of XML, which is being readable. Why can’t we just use an XML like syntax for this, like:

<entity name="client">Canol</entity>

Ok, the user should be able to define his/her own element named entity, so let’s write it like this:

<!entity name="client">Canol</!entity>

So, a predefined element (like keywords in other languages) are beginning with exclamation mark.

You can also use entities which are not to be replaced by XML processor and then it looks even uglier, like:

<!ENTITY mypicture SYSTEM "canol.gif" NDATA GIF>

You cannot even guess why we wrote words like SYSTEM, NDATA and GIF. You should learn this weird rules of XML. It is like learning what the parts before and after semi-colons do in for loops in languages like C:

for (part 1; part 2; part 3)

You cannot guess them, you should read the rules for writing for loops from somewhere. But, for example, in Python:

for i in range(1, 5)

You can most probably guess what i does here, right? And the above example could be:

<!entity name="mypicture" type="ndata/gif">canol.gif</!entity>

XML is full of such interesting things, even <!-- and --> look ugly to me. Was there really no other way, that they have to come up with these things? Then why are they allowing us to define the xml version like this:

<?xml version="1.0"?>

And not like this:

<![[?--XML version SYSTEM COMPUTER "1.0" MEMORY CDATA REFRIGERATOR--?]]>

Filed under: Programming, ,

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, , ,

Steve Dekorte’s Io Programming Language

I met Io programming language a few weeks ago. It is very simplistic, minimalist and has a consistent syntax. It is a fully object oriented language inspired by Smalltalk. A significant difference from Smalltalk is that it is prototype based, so there are no classes.

To name a few advantages and disadvantages:

Advantages:

  • Very consistent syntax
  • Very minimalistic rules
  • Has a lot of useful methods that makes your life easier
  • Very polished source code
  • Very informative and polished errors
  • Chic documentation

Disadvantages:

  • I like the writing style:

    "Hello" at: 1 put: "a"

    instead of

    "Hello" atPut(1, "a")

    Because it is more human like.

  • Indexing begins from 0 not from 1.
  • I don’t like when a language does not want you to declare your variables before usage. I think declaring obligatory provides some kind of documentation to the user of a program.
  • Some methods does not behave what you would like it to. For example, when you write

    "Hello" at(1)

    You get the byte representation and not the letter itself.

  • Resulting elseif structures look a bit ugly.
  • No GUI library bindings yet

Of course these are all subjective.

I think the worst disadvantage is that it does not have GUI binding yet. But once it has, then it will be a killer programming language.

Filed under: Programming, ,

Dear Diary

Part I of Blue Book is almost complete, actually I read it but didn’t understand the metaclass concept, so I will read last chapter again. Then I am thinking of going through the GNU Smalltalk tutorial so that I can learn the differences between Smalltalk-80 and GNU Smalltalk syntax. Part II is the longest part of the book but once complete I will be able to do practical programming with GNU Smalltalk.

It is good that I didn’t loose my interest in GNU Smalltalk yet 🙂 Actually, I’m looking forward to do some GUI stuff with it. Especially, after seeing the beautiful problem Bichromat had written to Ubuntu forums (http://ubuntuforums.org/showthread.php?t=803474)…

I guess GNU Smalltalk is supporting Tk and GTK.

Filed under: Programming, , ,