Ruby artisans on suicide watch

Ruby artisans on suicide watch

>interpreted vs compiled language
>hurr why use wood instead of sand

>whos more pretensious?

"Haskellers" wins yet again!

hurr durr beautiful compact code
spend minutes verifying a single line

>over 80 characters long
Absolutely disgusting

but user, that one line of haskell is way harder to read and write and doesn't look as good

import qsort;
qsort.sort(fuck_you)

python wins again

>lets make variable names shorter and non-descriptive, and stuff everything into a single line
>so terse
>so beautiful

x:xs is a pretty common Haskell naming convention that gets the point across.

It probably went over your webdev-tier brain desu senpaialam ding dong.

>x:xs is a pretty common Haskell naming convention that gets the point across.
irrelevant. the names are still less descriptive and readable that in the upper section
>webdev
not really and I even like Ruby and hipsters programming in it are obnoxious, but Haskell fags are the worst

If you've never programmed in the language, sure. I don't see that as much of an issue since it's supposed to be generic, and x is a generic enough name. (x:xs) already tells you that it's a list. Less is more in this case.

Then again you could use list as the name alongside the head/tail functions but I'd argue that would make it less readable.

I agree on that comment about Ruby/Haskellfags though.

>let's compare two entirely different programming paradigms based textually
sounds good OP

> ;

If you want a practical and pragmatic functional language, use Clojure.

Haskell is for autistic nerds who value purity and arcane (if aesthetic) syntax over anything usable.

Ruby is for light scripting as was never meant to become a massive dependency-laden mess used in major parts of the web's infrastructure.

I don't know about the Ruby one, but the Haskell code is not true QuickSort, it's asymptotically quadratic in best case.

One is readable and the other is unnecessarily compact.

let rec qsort cmp = function
| [] -> []
| x :: xs ->
let rec loop lower greater = function
| [] -> lower, greater
| y :: ys ->
let lower, greater =
if cmp x y < 0 then
lower, y :: greater
else
y :: lower, greater in
loop lower greater ys in
let lower, greater = loop [] [] xs in
let greater = qsort cmp greater in
let lower = qsort (fun a b -> - cmp a b) lower in
List.rev_append lower (x :: greater)
;;

let print l =
List.iter (fun n -> Printf.printf "%d " n) l;
print_newline ()
;;

let test l =
print_endline "======================================================\
==================";
print l;
let l = qsort ( - ) l in
print l
;;

let mk_list n =
let rec loop accu = function
| 0 -> accu
| n -> loop (Random.int 90 + 10 :: accu) (pred n) in
loop [] n
;;

let main () =
Random.self_init ();
test [];
test [42];
test [3; 1; 4; 1; 5];
test (mk_list 20);
test (mk_list 20);
0
;;

let () = exit (main ());;

let qsort cmp l =
let rec qsort accu = function
| [] -> accu
| x :: xs ->
let rec loop lower greater = function
| [] -> lower, greater
| y :: ys ->
let lower, greater =
if cmp x y

1. The Ruby code appears to be more readable.
2.
list.sort!

In any case, Haskell and Ruby aren't exactly comparable languages. Haskell is statically typed and compiled, Ruby is dynamically typed and interpreted. Haskell is functional, Ruby is multi-paradigm with a heavy emphasis on smalltalk-style object orientation.

> unnecessarily compact
That is the best way to do it. It's literally saying:

> Put the first item in the middle and quicksort the things less than it onto the left, and quicksort the things greater than it on the right.

> list.sort!
Now quicksort the days of the week with the same function.

OCaml or F#? Hell, it might work in both.

>F#
Absolutely disgusting. I have taste. Why would I use a slower and less safe language? I am not stupid.

literally 100% victory

ruby hipsters and haskell neckbeards on suicide watch

why even compare them. haskell is still a nightmare to integrate with postgres and even serve up a simple json api.

what we really need is a high level functional language with a killer webdev library. rails is already old shit, but the new shit like meteor is terrible. what the hell are you all doing CS people? us web devs aren't smart enough to alleviate our own condition

To all practical matters this

This. Haskell is an esoteric programming language by my book.

Define the operator for your "day of the week" class. Done. Alternatively, use
list.sort_by! { |a,b|
# Your method of comparing days of weeks here
}

>haskell wins

Oh god, you really have some issues, man.
Every langauge has pros and cons, for example, I'd like to see this in Haskell:


# put http article in text file

require "open-uri"

remote_data = open("en.wikipedia.org/wiki/Ada_Lovelace").read
File.open("my-downloaded-page.html", "w") { |f|
f.write(remote_data) }

>If you want a practical and pragmatic functional language, use Clojure.

If you really want to to leverage a functional langauge, you can just use Elixir, which has a syntax almost identical to Ruby (it was created by a ruby guy) and runs the Erlang Virtual Machine, arguably the best language for massive concurrent applications.

Also languages like Scala or Swift took many of Ruby's concepts (I wonder why??)..
Good language design is good language design, period.

toppest

>x:xs
That's fucking stupid though, and would take quadratic time on an already-sorted list.

Of course, you gloss over that in attempt to prove how superior Haskell is.

>would take quadratic time on an already-sorted list
1) You seriously don't know how complexity work in Haskell.
2) quick sort has quadratic complexity, Haskell is not guilty.

>the fewer number of lines it needs to implement quicksort, the better the language is

Said no one ever.

>require "open-uri"
Just use curl.

data Weekday = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday deriving Ord

quicksort [Friday, Tuesday, Monday]

I don't like Ruby at all, I'm a C# developer for a living, and I don't know Haskell at all

The Ruby code is at least intuitive. I can understand what is going on without knowing Ruby's specific syntax

The Haskell code on the other hand just looks fucking alien to me.

qsort is an array and is initialized to an array (I think) ?

Then qsort is now a delegate function all of the sudden? What is filter, what is being incremented with the ++?

All of these questions probably have simple answers but my point is it isn't intuitive at all.

"Beautiful" code is subjective, I suppose.

As someone who knows no C at all, and mostly Lisp/Haskell/Clojure, the Haskell just 'looks' right. I can't describe how, I guess I haven't been brought up in the imperative mould.

PS. qsort is a recursive function, filter is also a function. The list given to qsort is destructured into its first element 'x' and the rest of the list 'xs', allowing qsort to work on it element-wise.

It's defined like it would be in a logic programming language:
qsort of an empty list is an empty list
qsort o a list of at least one element (first element bound to x, the rest of the list bound to xs) is
- qsort applied to the list obtained by filtering elements not < x from xs
- x
- qsort applied to the list obtained by filtering elemtns not >= x from xs
(contatenated in that order)

I don't know haskell but I know scheme and a little logic programming.

Without defining a new type, the equivalent in Ruby might be something like this:

Weekday = { sunday: 0, monday: 1, tuesday: 2, wednesday: 3, thursday: 4, friday: 5, saturday: 6 }
[:friday, :tuesday, :monday].sort { |x,y| Weekday[x] Weekday[y] }

He said C#. Not C.

> qsort o a list of at least one element
qsort of a list of at least two elements.

A list of one element would be
[x]

... wat

How do you expect any enterprise-scale web application to function without a server-side language

Where would you put the business logic? Would you not use an ORM?

just... wat.

Does it not work like lists in scheme where
(first '(a))
=> a
(rest '(a))
=> '()
?
(using first instead of car and rest instead of cdr for readability)

erm, I guess it was a troll.

I guess its just a different kind of programming I'm not used to, then.

I got about 1/3rd of the way through SICP a couple years ago and lost interest because... well I just didn't see any practical applications of that particular language

Are these languages (scheme, haskell) used anywhere besides leisure programming and AI ?

(just in case it needs clarification:
(first '(a b c))
=> a
(rest '(a b c))
=> '(b c)
)

You can do that, but not in destructuring pattern matching.

Pattern matching on (1) an empty list, (2) a list of one element, (3) a list of at least two elements:
fn [] = ...
fn [x] = ...
fn (x:xs) = ...


You can pattern match as many elements as you like this way.

If you want to use 'head' or 'rest', you can use guards:
fn list
| (head list) == x = ...
| (head (tail list) == y = ...
| otherwise = ...

So then how does the code in OP behave when there is one element in the list? Shouldn't xs pattern match to an empty list?

> Are these languages (scheme, haskell) used anywhere besides leisure programming and AI ?
I have no idea, I'm a chemist who does Haskell/Lisp/etc. for fun.

They're used all over the place by people who like them. idk if there's enterprise sort of jobs available. More the sort of jobs where your boss doesn't care what tool you use to get the job done.

So then why is there even a debate between Ruby and Haskell?

They aren't even used in the same way. I don't understand this thread at all.

I'm leaving now.

> Shouldn't xs pattern match to an empty list?
Yes, indeed it does.

In Haskell, lists are usually written as
[1,2,3,4,5]


But this is just syntactic sugar for how it is really interpreted:
1 : 2 : 3 : 4 : 5 : []

The ':' is the 'cons' from stuff like Lisp, and every list terminates with an empty list, so a list of one element is
1 : []


So in the OP's code, the pattern '(x:xs)' matches, for example, the '1 : []'.

You could write a Ruby version which looks a little bit more like the Haskell version:

(I didn't test this, so..)

def qsort(xs)
return xs if xs.size = x))
end

>I'd like to see this in Haskell
Not OP but here:

import Network.Wreq
import Control.Lens
import qualified Data.ByteString.Lazy as BS

main = do
response

>terse and beautiful code
>not Lisp
Ayy

Looks nice!
A lot of libraries though..

Aaa, I fucked up..

def qsort(list)
return list if list.size = x} )
end


As you see, this version is pretty close to the haskell version:

1. if one element, return
2. get the first element (in haskell it's implicitly done with "x:xs")
3. return the group smaller + pivot element + the group bigger


So at the end of the day, Haskell is a great language and Ruby is, so why am I writing at this stupid cambodian motorcycle board again..?

There shouldn't be. Language wars are idiotic and only perpetrated by trolls and those who don't understand what they're saying.

I don't know Haskell and I can read that line in 15 sec

Not true, [] is not technically an element, it's the terminating constructor. (x:xs) matches any list of one element or more. [x] matches a list of only one element.

I am all for descriptive variables.
In this example there is no reason for them though. There is no need for pivot, no left or right.
No description necessary since the structure in that line shows what happens. Just work with the list and x:xs is perfect for that.
>ruby btfo

>(++) Appends two lists
Then it's a lot more clear what's going on.

[1] == [1] ++ [] == 1:[]

Yes.
Facebook uses Haskell and read about some finance company using it.

>Scala took many of Ruby's concepts
u wot m8?
Scala is basically haskell on jvm
elixir is good tho, gonna learn it in a couple of months probably. Clojure's where it's at imo.

>I don't understand the syntax of something I've never learned
do shitposters shitpost

>functionnamethatisverylongbecauseImretarded (theheadofthelist:therestofthelist)

lmao lets see the Makefile

Elixir is pretty neat, fast as fuck. So is Clojure.

Quicksort is in-place and swaps elements of the array.

someone do a clojure version

because ocaml still can't operator overload

not when it's shorter lines, easier to understand and cleaner

>1) You seriously don't know how complexity work in Haskell.
I don't think I've heard of anything stupider. Complexity isn't something programming languages can magically be immune to.

>2) quick sort has quadratic complexity, Haskell is not guilty.
Only in the worst-case, e.g. when you're sorting an already-sorted list, which your stupid fucking code snippet wouldn't know how to handle.

>massive dependency-laden mess used in major parts of the web's infrastructure.
I agree. "require" is the worst fucking thing about Ruby.

he didn't day it didn't have time complexity, he said you don't know how it works

>reddit

Fuck off
u
c
k

o
f
f

I don't give a flying fuck how short the fucking source code is. Programming languages do not exist to exploit their syntaxes to write obscure condensed code that needs to be read ten times to understand. They exist to be human readable. As long as it produces machine code of equivalent performance, the code can be as long and descriptive as it needs to be. I don't need to impress my nerd friends with obscure code.

>he can't understand the code from looking at it for a few seconds
I bet you think all code is supposed to be understood at sight
Its understandable, I mean, the only code you look at is fizzbuzz.

>Swift took many of Ruby's concepts
which? it was very much inspired by Rust and Haskell (for example, protocols vs. traits vs. type classes)

>that monstrous sequence of characters
>beautiful

Shit taste taken to a pathological level.

Clojure

(defn quick-sort
[lst pred]
(if (empty? lst)
[]
(let [car (first lst)
cdr (rest lst)
cmp (fn [x] (pred car x))
left (quick-sort (filter cmp cdr) pred)
right (quick-sort (filter (complement cmp) cdr) pred)]
(concat left [car] right))))

ex.
=> (quick-sort [2 3 89 9 1] >)
(1 2 3 9 89)

>beautiful
missed that part.

he wrote it like shit
here's a better version

import Data.List
qsort [] = []
qsort (x:xs) = s ++ [x] ++ b
where (s, b) = partition (

This code is very straightforward though

Even better
sorted(listy)

not quicksort
just mergesort
also
>()

Java masterrace reporting in

> you can do retarded 1 liners that make no sense

if obfuscation = good C wins

sort list

checkmate mommy

It's timsort

[3,5,9,1,6,2,8,4,7].sort()

How does your stupid haskell oneliner avoid sorting in O(n^2) when processing a sorted list, then? If you're going to call me out on my (correct) assertion, at least bring some facts.

cool
let rec qsort = function
| [] -> []
| x::xs ->
let s,l = xs |> List.partition ((>=) x)
qsort s @ [x] @ qsort l

Here's a Clojure version based on this, not quite as nice given Clojure's incompatibilities between collection types.

(defn qsort [coll]
(let [x (first coll)
xs (rest coll)]
(condp = [x xs]
[nil '()] []
(let [[l s] ((juxt filter remove) #(>= % x) xs)]
(vec (concat (qsort s) [x] (qsort l)))))))

that isn't even quicksort.

This is the problem with Python skript kidZ, they learn to "just use the existing library"

shoo

Haskell and Scala are not even remotely similar. Completely different syntax, semantics, data modeling, everything, frankly.

>rewriting 50 year old algorithms by hand

freetards

>implement quicksort
>>rewriting 50 year old algorithms by hand

Are you retarded?