Buscar en este blog

martes, 5 de abril de 2016

Y si se usara el esperanto en los lenguajes informáticos

Aprovechando el día 1 de abril, día de los inocentes en el mundo anglosajón, hicieron un anuncio explicando las bondades del idioma esperanto y cómo ayudaría a los desarrolladores, lo cierto es que las razones expuestas y la mayor parte de comentarios indican una favorable adopción del esperanto:

Lenguaje crystal: https://github.com/crystal-lang/crystal/issues/2394

Closed
asterite opened this Issue · 26 comments

19 participants

Crystal Language member asterite commented  
 
Saluton!
We wanted to propose this for a long time and now we have gathered enough evidence to think this is a good idea.
What if we make Esperanto the default language used by Crystal? With this we don't mean just the official docs, but the language itself: the keywords, the classes, the methods, etc.
Why? Well, I'll enumerate the reasons in no particular order.

1. Question and bang methods

Right now some methods have a question method at the end. For example:
array.empty?
I believe the reason Ruby did this, and why we copied this rule, is because this:
array.empty
is confusing: will it empty the array or is it asking if the array is empty? Of course an alternative is to use array.is_empty, but that reminds us of more verbose languages so we prefer to avoid that.
The real reason is that the gramatical use of a word is not clear in English: "empty" can be both a verb and an adjective.
In Esperanto a word's gramatical meaning is encoded in itself via its ending:
  • If a word ends with "a" then it's an adective
  • If a word ends with "i" it's a verb
So, in esperanto it could simply be:
aro.malplena
No confusion: it ends with "a" so its an adjective. Here "malplena" means "empty". "Plena" means "full", and the prefix "mal-" gives the exact opposite meaning of a word (I'll talk about this later).
(By the way, note that "aro" ends with "o": all nouns end with "o".)
Then to empty an array we currently have array.clear (which, by the way, might be bringing the same confusion as empty). In Esperanto it will be:
aro.malplenigi
The suffix "-ig-" (put before the gramatical indicator of a word) means "to make something ..." or "to turn something into ...". In this case it means "to make something empty". How more obvious can it be? Right now in Ruby there are many aliases, and I believe it's because you can express yourself in English in too many ways. In Esperanto there's always a clear, obvious way, so the language's vocabulary becomes more intuitive by design.
Also talking about the "-ig-" suffix, we could have:
aro.kolekti { ... }   # same as `array.map  { ... }`
aro.kolektigi { ... } # same as `array.map! { ... }`
because "-ig-" means "to turns something into". The bang method becomes redundant and we could use it for another meaning, maybe "not_nil!".
This will also free the question symbol. We could use it for the "lonely operator":
foo.try &.bar # current syntax
foo?.bar # new syntax
It's a win-win situation.

2. US vs UK

We received many complaints about some Ruby/Crystal methods. The most obvious ones are "initialize" and "finalize". Some messages we received in private and IRC:
  • Why "initialize" instead of "initialise"?
  • I always find this confusing, can we maybe choose another name?
We agree, the name must change. But since there's no obvious good candidate (US or UK?), it seems fair to switch to a neutral language.
The names for "initialize" and "finalize" in Esperanto will be "iĝi" and "maliĝi". "iĝi" means "to become" (note the similiarity with the word "igi" described above). The prefix "mal-" gives a word its opposite meaning so "maliĝi" means "cease to exist". Wouldn't this be super awesome and intuitive in a language? I mean, there's no obvious relation between "initialize" and "finalize", if you look at them.

3. ! (not)

In Esperanto you can attach the "ne-" prefix ("ne" means "no") to give a word the meaning "not ..." (note that this is different from "mal-" which gives a word its total opposite meaning). So, we could make the language recognize methods starting with "ne" to mean "!...". For example:
se koekto.malplena # if array.empty?
  # ...
fino # end

se aro.nemalplena # if !array.empty?
fino # end
Of course this is just syntax sugar, but if you read it in Esperanto it's a gramatically correct sentence. However, "if not array empty" is not a valid English sentence.

4. Learn Crystal, learn Esperanto... and the other way around

We believe both Crystal and Esperanto need to grow. If learning Esperanto means you can also start programming in Crystal, and if learning Crystal means that you can start to speak Esperanto, then its a mutual help where both parties could really benefit.
Not to mention that learning Esperanto opens your mind to other languages, and makes it easier to learn them. For example after I learned Esperanto I learned French and it was very easy: "fenêtre" in French is "window", and in Esperanto its "fenestro". Or you re-learn (because you probably learned that in school) about direct objects, and how in Esperanto you use "-n" for this, and how in Japanese you use "を" for the same purpose.
It's also the case that learning Crystal opens your mind for learning other programming languages :-)

5. Why English?

We don't see any particular reason to choose English over another language other than "it's the lingua franca of the moment". In a previous century it was French, so why choose a language that might stop being used that much? In any case docs for Crystal are still made for other languages, like Japanese, Portuguese and Russian, which probably means that not everyone understands English very well.
Esperanto has the benefit that (almost) no one is born knowing it so nobody has an advantage over somebody else (for example native English speakers always feel at home with programming languages), so it's only fair to use a neutral language. Many also compare Esperanto with Unix, calling it the "open source" spoken language.

Final notes

Here's a small code example written in the future language:
klaso Aro
  dif malplena
    @grandeco == 0
  fino
fino

aro = [] de Int32
se aro.malplena
  printi "La aro estas malplena"
sene
  printi "La aro havas #{aro.grandeco} erojn"
fino
(If you find the above confusing it's probably because of lack of proper syntax highlighting)
We believe that as we will translate the language to Esperanto we will find many more cases where Esperanto's clear and concise rules will benefit the language.
What do you think? We'd love to know your opinion on this!

Los comentarios que siguieron al anuncio fueron normalmente a favor y permiten observar que conocen bien el idioma:
Mi tute konsentas! :+1:

... leer más ... legu plu ...

No hay comentarios:

Publicar un comentario