News for hackers. Stuff that matters.
Re:Study of non-programmers' solutions to programming proble... by grapevines on Friday April 15, 2016 @10:38PM (#11509034)
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
Re:Study of non-programmers' solutions to programming proble... by freditup on Friday April 15, 2016 @11:20PM (#11509143)
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.
Re:Study of non-programmers' solutions to programming proble... by im_down_w_otp on Friday April 15, 2016 @11:58PM (#11509230)

  -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 :-)
Re:Study of non-programmers' solutions to programming proble... by simoncion on Saturday April 16, 2016 @12:38AM (#11509335)
> 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.

Re:Study of non-programmers' solutions to programming proble... by eru on Monday April 18, 2016 @01:17AM (#11517847)
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.

Re:Study of non-programmers' solutions to programming proble... by simoncion on Monday April 18, 2016 @02:36AM (#11518070)
> 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.

Re:Study of non-programmers' solutions to programming proble... by simoncion on Friday April 15, 2016 @11:44PM (#11509192)
> 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
Re:Study of non-programmers' solutions to programming proble... by thrownaway2424 on Saturday April 16, 2016 @12:03AM (#11509240)
Typical C program, eh? Yet another reason to not program in C, I guess.

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

Re:Study of non-programmers' solutions to programming proble... by eru on Saturday April 16, 2016 @12:54AM (#11509384)
Wow, that's pretty verbose. But I guess the long variable names are partly to blame.
Re:Study of non-programmers' solutions to programming proble... by jackweirdy on Saturday April 16, 2016 @05:58AM (#11509997)
Haskell:

let listsum = foldl (+)

Re:Study of non-programmers' solutions to programming proble... by tome on Saturday April 16, 2016 @10:03AM (#11510621)
You probably want foldl' (+) 0
Re:Study of non-programmers' solutions to programming proble... by codygman on Saturday April 16, 2016 @12:28PM (#11511161)
foldl1 (+) ?
Re:Study of non-programmers' solutions to programming proble... by ufo on Saturday April 16, 2016 @01:34PM (#11511463)
I think its better to give a same result to the empty-list case when its possible.