Hacker News new | ask | show | jobs
by grapevines 3718 days ago
For example, a typical C program to compute the sum of a list of numbers includes three kinds of parentheses and three kinds of assignment operators in five lines of code

Let me take the opportunity to plug a new language which I have spent the last 5 months designing: github.com/jbodeen/ava

An ava solution -- 9 lines of code, and 1 set of parentheses -- would look like this:

  let rec sum list = 
    let are_we_at_the_end = 0 in
    let take_a_number_and_the_rest_of_the_list n list =
      add n ( sum list )
    in
    list 
      are_we_at_the_end
      take_a_number_and_the_rest_of_the_list 
    in
Maybe we need to zoom out of ancient languages into more intuitive paradigms if programming is to become easier for more people to access
6 comments

Could you elaborate on how this is more understandable to a novice than the typical C program? My guess is that neither is immediately understandable, and that the C program is clearer to someone experienced.

  -module(math).
  -export([sum/1]).

  sum(ListOfNumbers) ->
      sum(ListOfNumbers, 0).
  sum([Number | RestOfList], Subtotal) ->
      sum(RestOfList, Subtotal + Number);
  sum([], Total) ->
      Total.
edit: blargh... sorry @simoncion, I didn't see your reply. It apparently takes me longer than 14min to type that out on my phone without typos + proper spaces to treat it like code :-)
> sorry @simoncion...

No worries. It's astonishing how absolutely awful on-screen phone keyboards still are for doing anything more involved than writing a brief human-language message.

That's because they are optimized for that.

No reason, apart from economics, why even with current IDE technology we couldn't make one that works well for specific programming languages.

> That's because they are optimized for that.

That's like a big chunk of my point. :) Phone/tablet keyboards really suck for anything other than short human-language text entry. You wanna write a five-page paper? A code snippet to demonstrate a problem? Forget about it.

It's astonishing that these devices have been around for at least seven years and their packed-in keyboards still fail at these tasks.

> Maybe we need to zoom out of ancient languages...

Maybe. Compare your function to the equivalent Erlang one:

  sum(L) ->
    sum(L, 0).
  sum([], Acc) ->
    Acc;
  sum([Num|Rest], Acc) ->
    sum(Rest, Acc+Num).
Assuming that it's in a module called 'math', run it like so:

  math:sum([5,4,3,2,1]).
  15
Typical C program, eh? Yet another reason to not program in C, I guess.

sum = std::accumulate(begin, end, 0);

Wow, that's pretty verbose. But I guess the long variable names are partly to blame.
Haskell:

let listsum = foldl (+)

You probably want foldl' (+) 0
foldl1 (+) ?
I think its better to give a same result to the empty-list case when its possible.