A couple of questions (Strings, OO, Server, Compilation)

215 views
Skip to first unread message

Ben

unread,
Aug 30, 2012, 9:54:55 AM8/30/12
to elixir-l...@googlegroups.com
hi

I'm exploring Elixir and also Erlang. My target is to use it for a small
web application. Since there is a lot to learn when it comes to Erlangs
concurrent facilities, my intention was to start using Elixir like a
arbitrary general purpose language and the approaching the concurrent
stuff step by step.

From what I can see now that is that Elixir is in some cases a reaction
to Erlang. Or should I say was?

## Strings
While reading about Erlang one of the most raised concerns in regard of
everyday programming is Strings. So the first thing I did was looking
for a string module in Elixir. There is none. Wouldn't that be handy? I
mean String.length, String.rev and stuff like that.

## OO
A few sources on the web about Elixir mention a thin OO layer. Is this
something that has changed into a more clojure-like, interface-centric
concept? I cant't see any reference to OO in the current docs.

## Server Example
Ok, this is simply a suggestion, or maybe a wish. I think it would be
cool to show with a simple example how to setup and start a server. At
every important Node.js side you meet that async server example. I'm
sure that there is something similar laying around. It would be nice to
make it more visible. At least showing a small example in the
GettingStarted section.

## Compilation
My last wish. An entire sample how to build and run code with elixirc.

Thanks for the great work on Elixir.

Ben

José Valim

unread,
Aug 30, 2012, 10:04:24 AM8/30/12
to elixir-l...@googlegroups.com
I'm exploring Elixir and also Erlang. My target is to use it for a small web application. Since there is a lot to learn when it comes to Erlangs concurrent facilities, my intention was to start using Elixir like a arbitrary general purpose language and the approaching the concurrent stuff step by step.

Welcome!

My target is also to use Elixir for (not necessarily small) web applications.
I am working on a web framework for Elixir too (http://github.com/josevalim/dynamo).
It is currently under work but we should have an alpha release by the end of September.
If you want to try or play with it regardless, join us at #elixir-lang on freenode and feel free to ask me (josevalim).
 
## Strings
While reading about Erlang one of the most raised concerns in regard of everyday programming is Strings. So the first thing I did was looking for a string module in Elixir. There is none. Wouldn't that be handy? I mean String.length, String.rev and stuff like that.

You are correct. Check the Binary module. :)
 
## OO
A few sources on the web about Elixir mention a thin OO layer. Is this something that has changed into a more clojure-like, interface-centric concept? I cant't see any reference to OO in the current docs.

Yes, we have moved away from OO (it didn't suit well with immutability). We are working with behaviours (from Erlang, somewhat similar to interfaces) and protocols (similar to Clojure's).
 
## Server Example
Ok, this is simply a suggestion, or maybe a wish. I think it would be cool to show with a simple example how to setup and start a server. At every important Node.js side you meet that async server example. I'm sure that there is something similar laying around. It would be nice to make it more visible. At least showing a small example in the GettingStarted section.

Yes. We will reach this point eventually.
There is still a bunch of work to be done in docs, we will get there slowly.
Contributions are always welcome, if you want any help, come to #elixir-lang!
 
## Compilation
My last wish. An entire sample how to build and run code with elixirc.

There is a mix chapter on the getting started guide that talks about creating and building Elixir projects:


Is that enough? What could be improved? 

Thanks for the great work on Elixir.

Thank you for the feedback!

José Valim

unread,
Aug 30, 2012, 10:25:45 AM8/30/12
to elixir-l...@googlegroups.com
Ah, if you want to use Dynamo, you will need to install Elixir from master (there are instructions for it in the getting started guide).


José Valim
Founder and Lead Developer

Ben

unread,
Aug 30, 2012, 10:36:30 AM8/30/12
to elixir-l...@googlegroups.com
> You are correct. Check the Binary module. :)

Yes, I was aware the that, but that is still a bit meager (sorry for the
negative word).
What is your take on Erlangs string processing? I mean is this something
Elixir should do fundamentally better? How much of a priority is it for
you?

From my very distant standpoint it shouldn't be too difficult to make a
potential 'string.ex' part of the standard library. Scripters like me
are confused without ssssstrings :-)

José Valim

unread,
Aug 30, 2012, 10:55:34 AM8/30/12
to elixir-l...@googlegroups.com
Yes, I was aware the that, but that is still a bit meager (sorry for the negative word).

Agreed. I am adding functions to the Binary module slowly. If you feel like you need other functions, like delete, tr, gsub, sub, replace, etc, feel free to contribute! I will gladly review your pull requests and exchange ideas.
So far, I am adding just the functions I need when working on other Elixir apps and libraries. So the growth right now is rather organic and slow.

What is your take on Erlangs string processing? I mean is this something Elixir should do fundamentally better? How much of a priority is it for you?

I think we already have a good foundation. We have a first class syntax for utf-8 binaries, we have a nice syntax for regular expressions which does not force you to double escape everything. We just need to improve the built-in modules and functions, but that is the easy part. :)

It definitely has high priority, but since it is mostly me working on Elixir (and other libraries) right now, it takes time. That's why contributions are welcome! (and a great way to learn Elixir and Erlang!) ;)
 
From my very distant standpoint it shouldn't be too difficult to make a potential 'string.ex' part of the standard library. Scripters like me are confused without ssssstrings :-)

The Binary module for now is supposed to do everything you would expect from a bare "string.ex". The reason I don't want to call it String is because we are not exactly sure what a String is. Is it a list? Is it a binary? Both? Maybe a String module works with binaries but all functions are utf-8 aware (for example, size would return the number of utf-8 endpoints instead the number of bytes)?

Cheers,

Ben

unread,
Aug 30, 2012, 11:28:09 AM8/30/12
to elixir-l...@googlegroups.com
Thanks for your interesting answers, one thing

> The Binary module for now is supposed to do everything you would expect
> from a bare "string.ex". The reason I don't want to call it String is
> because we are not exactly sure what a String is. Is it a list? Is it a
> binary? Both? Maybe a String module works with binaries but all
> functions are utf-8 aware (for example, size would return the number of
> utf-8 endpoints instead the number of bytes)?


hmmm, this seems to be no easy task. What if you were looking from the
outer side, not caring about the Erlang internals/semantics.

Try to stand in my shoes:

"I want the length of this string". String.length! Boom.
Or String.force-encoding("utf8")! Bam

I don't want to dance around dualities that might origin or not from
Erlang. Not from where I stand now.

Ok - is still still helpful? Probably not ...

Benoit Martel

unread,
Aug 30, 2012, 12:55:49 PM8/30/12
to elixir-l...@googlegroups.com
Hi Ben,

Regarding this part of your question:

> ## Server Example
> Ok, this is simply a suggestion, or maybe a wish. I think it would be cool
> to show with a simple example how to setup and start a server. At every
> important Node.js side you meet that async server example. I'm sure that
> there is something similar laying around. It would be nice to make it more
> visible. At least showing a small example in the GettingStarted section.

I have had a very good experience working through the E2 tutorial as a
way to become more familiar with both Erlang and Elixir. E2 is a
simplified Erlang wrapper around the basic server behaviors from OTP.
It can be used as a gentle introduction to concurrency programming in
Erlang and get you to the point where you will be able to learn by
yourself the details of advanced OTP programming later. Since the
tutorial is in Erlang and I was actually following along by writting
all the code in Elixir, it really forced me to understand how things
work in practice and how to handle differences (e.g. I used binaries
while the example was using strings). I recommend it to anyone who
isn't already experienced with Erlang and wants to learn Elixir.

The website is: http://e2project.org/.
The quick start page shows you how to install E2 etc:
http://e2project.org/quick_start.html.
The interesting part is the tutorial where you build a disk-based
key-value store (database) that responds to queries over TCP sockets:
http://e2project.org/quick_start.html.

Regards,
-Ben

Ben

unread,
Aug 31, 2012, 7:30:33 AM8/31/12
to elixir-l...@googlegroups.com
Very interesting, thank you Benoit.

Now the obvious question: Is you code from the Elixir port somewhere
available?

Benoit Martel

unread,
Sep 3, 2012, 9:16:10 PM9/3/12
to elixir-l...@googlegroups.com
Hi Ben,

I didn't have time to review it and set it up on github. I figured
sending this directly was better than sending nothing.

Here is my Elixir source code for the E2 tutorial. You can just put
these files in the source directory of the tutorial, replacing the
Erlang files there. I then use the following command to compile these
files: "elixirc -o ../ebin/. -pa ../deps/e2/ebin/. *.ex".

-Ben
MyDB_App.ex
MyDB_Client_Handler_Sup.ex
MyDB_Client_Handler.ex
MyDB_Data.ex
MyDB_DB.ex
MyDB_Server.ex
MyDB.app.src
MyDB.ex
Reply all
Reply to author
Forward
0 new messages