7 ms·
I spent some time doing several small programming exercises in Ioke. I've also done similar exercises in several programming languages ranging from C to Java to
by hammerdr 15y ago
I spent some time doing several small programming exercises in Ioke. I've also done similar exercises in several programming languages ranging from C to Java to Haskell to Ioke.
Ioke was ridiculously clean in almost every scenario. The only part I missed was that I didn't delve deep enough to really use the macros to their fullest extent. Something that would take 50 lines of idiomatic Ruby took 10 lines of Ioke. Ruby is already a very expressive language and yet Ioke could express the same thing in half the amount of code.
The author of this post is not kidding when he says that Ola designed the language with no regard for performance. The language is slow.
However, Ola is working on a language that learns from the expressiveness of Ioke but is a bit more practical. It's called Seph and is at http://www.seph-lang.org http://www.seph-lang.org
And, finally, a small story: I was spending a few nights a week writing Ioke and trying it out about a year ago. Ola spoke about Ioke at an internal company presentation (sort of a mini-conference) and afterwards I started to talk about the language with him and Brian Guthrie. We talked about the language constructions and how we solved problems in the language, etc. etc. Finally, I get around to asking the question, "So, after writing Ioke for these past few weeks, I feel like I have no idea if I'm writing idiomatic Ioke!" Both of them look at me as if I'm a crazy person and finally Ola smiles and says, "There need to be more than 10 developers writing in a language for there to be idiomatic anything." Playing with these languages are fun but messy! Don't be afraid to make mistakes and just dive in.
- riffraff 15y agocould you share an example of a ioke program with a 5x ratio to ruby code? I can think of many things that could be way less verbose in ruby, but I wonder where from does a a fivefold improvement come.
- hammerdr 15y agoI fear I am going to do a bad job of explaining this, but here goes: You'll get the typical Lisp-like terseness and folding that'll make your complex code much smaller. This includes things like currying and passing multiple functions as parameters (I know both of these are possible in Ruby, but it really isn't idiomatic). This one, I think, is easier to understand especially if you've done some work in those types of languages. The other benefit is more difficult to see at face value. What Ioke does is encourages you to write expressions and to build up your own language. This is a DSL and can be built in Ruby and Lisp and Javascript and many other languages. However, Ioke makes the DSL writing the "Pit of Success" that a developer encounters. It isn't a conscious choice, it is how you write your code. Simplistic example: square = lambda { |x| x * x } puts (1..10).inject(0) { |sum, x| sum + square.(x) } In Ioke: square = method(x, x * x) (1..10) map(x, square(x)) sum println This is obviously a trivial example that doesn't save any lines. They look very similar except that ruby has a bit more "noise". First, we're using the inject function. I love the inject function but it is a significant amount of noise in the ultimate goal of a readable line of code. Ioke has 4 words that are all significant: map square sum println. They are used once and only once. Ioke's space a function applicator cannot be overlooked, though. It is syntax, yes, but it really encourages "sentence writing" a la Smalltalk. And, finally, Ioke reads left-to-right unlike the C-inspired languages which read inside-out. In fact, if you were to describe this problem in English, you would probably write something similar to: For the range 1 to 10, square each number and then sum the results. Ioke maps very well to this. (1..10) map(x, square(x)) sum println The problem with this trivial example is that this expressiveness is just slightly off for Ruby. But when we grow the program to scale, in Ruby we lean on the classical inheritance-based Object Oriented model that is available in Ruby. In Ioke, we continue to build a DSL. I hope that makes a little sense? Edit: Let me also say that I'm madly in love with Ruby and think its a great language :) By no means does "Less Expressive than Ioke" mean "Not Expressive Enough" or "Bad Language"!
- rauljara 15y agoBut you can do the same map square, then sum in ruby 1.9: puts (1..10).map{|x| x*x}.inject(:+) And if you don't like writing inject(:+) all the time, it's pretty easy to monkey patch in a sum method to either array or enumerable.
- draegtun 15y agoAnd Perl6 can also provide an expressive example: say [+] (1..10).map: {$_ * $_};
- JadeNB 15y agoNo need to wait for Perl 6: my $tot = 0; map { $tot += $_ } map { $_ ** 2 } 1 .. 10; say $tot; EDIT: Or, regarding List::Util (http://search.cpan.org/~gbarr/Scalar-List-Utils-1.23/lib/List/Util.pm http://search.cpan.org/~gbarr/Scalar-List-Utils-1.23/lib/Lis...) as part of Perl 5, say sum map { $_ ** 2 } 1 .. 10; EDIT 2: (Golfing is fun!) Or an Applescript-y sub the { @_ } sub of { @_ } sub squares { map { $_ ** 2 } @_ } say the sum of the squares of 1 .. 10;
- draegtun 15y agoNo need to wait for Perl 6 Absolutely :) use autobox::Core; # or perl5i::2 [1..10]->map(sub{ $_ ** 2 })->sum->say; Or if you like a double helping of sugar in your tea! use Whatever; [1..10]->map( &_ ** 2 )->sum->say;
- JadeNB 15y agoI thought `Whatever` was a joke, and had to go look it up on CPAN (http://search.cpan.org/~asg/Whatever-0.21/lib/Whatever.pm http://search.cpan.org/~asg/Whatever-0.21/lib/Whatever.pm). Not to belabour a joke, but the examples there suggest that the map should be map( $* ** 2 ) not map( &_ ** 2 )
- beagle3 15y agoYou (and Ola ...) really should take a look at the APL / J / K family. All are 10-100x times more expressive than Ruby/Python, and 100x-1000x times more expressive than C and Java. They are all quite fast, with K being super-blazing-fast. I can't do these languages justice in a comment -- but have a look at https://github.com/kevinlawler/kona/wiki/Idioms https://github.com/kevinlawler/kona/wiki/Idioms and https://github.com/kevinlawler/kona/wiki https://github.com/kevinlawler/kona/wiki - you are in for a shock about how unexpressive everything you've used so far is (and you don't have to give up speed to get that)
- skrebbel 15y agoShort isn't equal to expressive. Making every operation a single character does not really help understandability, IMO.
- beagle3 15y agoAPL/K's expressiveness does not come from making every operation a single character (although they do work together nicely). It comes from selecting a good set of primitive elements and their rules of interaction. It turns out (for K) that ~40 primitives are sufficient to cover what you need, and it is therefore possibly to assign these to single ascii characters (20 unary, 20 binary; e.g. "xy" is multiplication, but "x" is "first element of x". Most languages overload unary/binary on the same symbol). Take, for example, the "maximum substring sum" problem (see link in the K idioms above). Using K syntax, it's |/0(0|+)\ Using Q syntax (K with words instead of characters), it becomes max over 0 (0 max +) scan Three times longer, hardly using any non-alphabet characters. Just as unreadable to the uninitiated, and still 10 times shorter than a comparable Python or ruby implementation. Once you do get used to thinking in APLish or Kish, then the first version to the second version is like "a+b*c-d" to "a added to b times c and then d is subtracted". I know which one I prefer. Short isn't equal to expressive, but your comment is irrelevant to APL or K.
- hvs 15y agoThe APL-family of languages aren't just short. Those single (and double) characters are each very powerful. APL was not based on the von Neumann style of programming. It is much more comparable to Haskell and the like.
- hvs 15y agoI went to a Chicago ACM presentation of Ola's a couple of years ago talking about Ioke. It was really pretty impressive. Seph (on the surface) actually reminds me a lot of Smalltalk.