[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Ruby rockstars really aren't that tough now are they?
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 23
Thread images: 1
File: better-than-x-8-728.jpg (66 KB, 942x728) Image search: [Google]
better-than-x-8-728.jpg
66 KB, 942x728
Ruby rockstars really aren't that tough now are they?
>>
>>53327884
is that haskell example seriously claiming to be terse and/or beautiful?
>>
Neither of those is a proper quicksort.

But you are right: Haskell is far more terse than Ruby. Haskell is the tersest language I know of that is even vaguely practical.
>>
I want someone to post the equivalent in java so that I can laugh at them, and then cry myself to sleep because I work in java.
>>
That's a pretty long line of haskell and if I didn't know what quicksort was it would be hard to read. Ruby is meh too though
>>
>>53328140
Everyone knows what quicksort is though
>>
>>53327884
try to explain to a college graduate who has never programmed what each does, line by line.
>>
>>53327910
I probably wouldn't write it like that. I would most likely do

quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) = quicksort left ++ [x] ++ quicksort right
where
(left, right) = partition (<x) xs


Using the partition function from Data.List.

The type signature is optional, of course.

I still find the original Haskell program more terse and beautiful than the Ruby program, though.
>>
>>53328235
Haskell is easier to read desu
>>
>>53327990
Collections.sort(list)


>>53328235
No. Why would I do that? That's a waste of time. Someone who does not do any programming has no need to look at or understand implementations of quicksort.

(Not that this is actually quicksort since it isn't in place.)

I'm sure I could explain it, but I can't imagine any situation in which I would have to. Only programmers and computers need to be able to understand programs. Users don't have to.
>>
>>53327884
Nice alliteration
>>
>>53327884
the haskell one is not quicksort
I wouldn't waste time on any of them tbqh
>>
>>53327884

That Haskell is disgusting. Code golf != beauty.
>>
>>53329637
This.

>look how much of a syntax stud I am

Once you actually work in the business you learn to hate bitches like this with a passion. I don't want to admire some faggot's attempt to be "terse and beautiful" I want to fix the fucking massive bug he created along with his masterpiece.
>>
>>53329637
That's not golfed. It is actually very clear if you're at all familiar with functional programming.
>>
>>53329637
Could you elaborate? It's pretty straight forward

(everything smaller than first, sorted) + first + (everything bigger than first, sorted)
>>
>>53327884
>not using php
>not sorting clientside wiht javascript

wtf are you doing??
>>
>>53331233
>>53331267

I do know what it's doing, but the fact is that code is designed to be small, and that doesn't equate to readability. >>53328255 shows how it should be done. I still think the (x:xs) idiom is wrong, but at least you get used to that.

It's no big deal when isolated like this, but when you have a real program doing this shit everywhere it can get painful, especially when point-free style is added to the mix.
>>
>>53328331
KAAK
>>
>>53327884
beat version here
qsort [] = []
qsort (x:xs) = qsort small ++ [x] ++ qsort big
where small = [i | i <- xs, i < x]
big = [i | i <- xs, i >= x]
>>
>>53327884
Consider the things: Haskell and Ruby were made with very different goals.

The ruby code in your example reads like pseudocode and can be used to show anyone how to implement the algorithm, while the Haskell is written as terse add possible. The ruby code van be written to be more terse, and the Haskell more obvious.

Both ruby and Haskell have built in sort functions, so writing this in either is an in class exercise only.
>>
>>53327884

main.whateverthefucklanguageIwant

standardLibrary.quickSortWithNoExtraCrap(data)

done

>living in dreamland zzz
>>
>>53331603
How would you rather pattern matching on head and tail be done?
Thread replies: 23
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.