Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Look Around You
Jan 19, 2009

shrughes posted:

In Coffeescript:

z = [0..2] becomes z = [0, 1, 2]

z = [0..1] becomes z = [0, 1]

z = [0..0] becomes z = [0]

z = [0..-1] becomes z = [0, -1]

Then there's z = [0...n], the secret feature which does what you want and isn't documented.

Comprehensions in Coffeescript are also not monadic:
code:
coffee> [x,y] for x in [0..3] for y in [4..8]
[ [ [ 0, 4 ],
    [ 1, 4 ],
    [ 2, 4 ],
    [ 3, 4 ] ],
  [ [ 0, 5 ],
    [ 1, 5 ],
    [ 2, 5 ],
    [ 3, 5 ] ],
  [ [ 0, 6 ],
    [ 1, 6 ],
    [ 2, 6 ],
    [ 3, 6 ] ],
  [ [ 0, 7 ],
    [ 1, 7 ],
    [ 2, 7 ],
    [ 3, 7 ] ],
  [ [ 0, 8 ],
    [ 1, 8 ],
    [ 2, 8 ],
    [ 3, 8 ] ] ]
vs.
code:
Prelude> [(x,y) | x <- [0..4], y <- [5..8]]
[(0,5),(0,6),(0,7),(0,8),(1,5),(1,6),(1,7),
(1,8),(2,5),(2,6),(2,7),(2,8),(3,5),(3,6),
(3,7),(3,8),(4,5),(4,6),(4,7),(4,8)]
(which is equivalent to:)
code:
import Control.Monad
testMonad :: [a] -> [b] -> [(a,b)]
testMonad a b = do
  aa <- a
  bb <- b
  return (aa,bb)

 testMonad [0..4] [5..8]
[(0,5),(0,6),(0,7),(0,8),(1,5),(1,6),(1,7),
(1,8),(2,5),(2,6),(2,7),(2,8),(3,5),(3,6),
(3,7),(3,8),(4,5),(4,6),(4,7),(4,8)]
Edit: tables. Also python!
code:
>>> [(x,y) for x in range(0,5) for y in range(5,9)]
[(0, 5), (0, 6), (0, 7), (0, 8), (1, 5), (1, 6),
 (1, 7), (1, 8), (2, 5), (2, 6), (2, 7), (2, 8),
 (3, 5), (3, 6), (3, 7), (3, 8), (4, 5), (4, 6), (4, 7), (4, 8)

Look Around You fucked around with this message at 01:59 on Dec 13, 2011

Adbot
ADBOT LOVES YOU

Vanadium
Jan 8, 2005

Well, the first example is more like [ [ (x, y) | x <- [ 0..3] ] | y <- [4..8] ]

Look Around You
Jan 19, 2009

Vanadium posted:

Well, the first example is more like [ [ (x, y) | x <- [ 0..3] ] | y <- [4..8] ]

EDIT: wait no.. How so?
If it were monadic it would return a [[0,5], [0,6], ...] instead of [[[0,5],[0,6]..][[1,5],...]]]

E2: I see what you mean, that still doesn't make sense for coffeescript to do it that way by default... I would expect a list comp to produce a flat list of the results, which in this case is a list of two integers. How would you represent the haskell thing in coffeescript then?

Look Around You fucked around with this message at 02:12 on Dec 13, 2011

shrughes
Oct 11, 2008

(call/cc call/cc)
That's just a parsing thing, it's parsing it as ([x,y] for x in [0..3]) for y in [4..8]

Look Around You
Jan 19, 2009

shrughes posted:

That's just a parsing thing, it's parsing it as ([x,y] for x in [0..3]) for y in [4..8]

Yeah, I see that, but if it's parsing it like that, there doesn't seem to be a way to get it to parse it the way one would expect it to parse it.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
I cannot for the life of me understand why it is desirable to have a special case (...) syntax for making the maximum of a range exclusive. It isn't at all clearer to read than simply saying n-1, and it sounds like a typo waiting to happen. This is the kind of thing that drives me nuts about Ruby and Perl.

Bozart
Oct 28, 2006

Give me the finger.

Internet Janitor posted:

I cannot for the life of me understand why it is desirable to have a special case (...) syntax for making the maximum of a range exclusive. It isn't at all clearer to read than simply saying n-1, and it sounds like a typo waiting to happen. This is the kind of thing that drives me nuts about Ruby and Perl.

While I haven't used whatever that stuff was, using exclusive upper bounds on ranges is great for things like spans of time. There would probably be an object for that which would attempt to do this for you. But anyway here's an example: you have a function that will tell you if a given date and time are considered "off peak" for the eastern us power grid. You want to know how many off peak hours are within a given week, say, the week starting 12/11/2011. Then you can call this function over the range [ 12/11/2011 .. 12/18/2011 ) and there is no ambiguity about the first hour of 12/18/2011.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Bozart posted:

While I haven't used whatever that stuff was, using exclusive upper bounds on ranges is great for things like spans of time. There would probably be an object for that which would attempt to do this for you. But anyway here's an example: you have a function that will tell you if a given date and time are considered "off peak" for the eastern us power grid. You want to know how many off peak hours are within a given week, say, the week starting 12/11/2011. Then you can call this function over the range [ 12/11/2011 .. 12/18/2011 ) and there is no ambiguity about the first hour of 12/18/2011.

I don't want to use a language designed by you. Date literal syntax? And yes, it seems terrible that we have two range syntaxes, when we only need one.

Also, somebody decided to take Sinatra, port it to Perl, and call it "RESTful". The result? Mojolicio.us

tef
May 30, 2004

-> some l-system crap ->
fffffffffffffffffffffffffffffff rest fffffffffffffffffffuck :smith:


to add: I had a recent run-in with a web2.0 gentleman who blindly asserted things are restful because they are called restful. I think I've long given up on people actually using rest to mean anything other than 'I am a total idiot and I have no idea how HTTP works'.

tef fucked around with this message at 07:45 on Dec 13, 2011

Deus Rex
Mar 5, 2005

edit: nm

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.
Why I hate strings in c++ on win32 platform...

quote:

// Convert from string to ULONGLONG.
//
// VT_UI8 is not supported on W2K.
// So we can't use a variant to do the conversion
// (which we could on other platforms).
//
// There is a _ui64tow_s and a _wtoi64, but no _wtoui64,
// so we have to use _wtoi64 and convert the string to a LONGLONG
// and put that in our ULONGLONG.
// If the string is greater then _I64_MAX, then _wtoi64 returns _I64_MAX.
// But that should be plenty big for all practical purposes.
//
// If _wtoi64 encounters an error it will set the value to 0.
// This would only happen if the XML element contains a bad string,
// in which case 0 is appropriate.
// If the string has a number in the front, it will take that number
// "123 bad string" returns 123.
//
// _I64_MAX == 9,223,372,036,854,775,807
// _UI64_MAX == 18,446,744,073,709,551,615

Bozart
Oct 28, 2006

Give me the finger.

Suspicious Dish posted:

I don't want to use a language designed by you. Date literal syntax?

I was just writing it in a readable way. Since I didn't know whatever language he was talking about I figured I would show an example where it would be helpful, other than the one you just showed. I'll be sure to keep away from designing languages too, my man.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
This one threw me for a couple of days :downs:

code:
public Butt Foo(long id)
{
    return Foo(id);
}

public Butt Foo(long id, IButt butt = null)
{
    // do stuff
    return someButt;
}

Opinion Haver
Apr 9, 2007

i barely GNU her! posted:

This one threw me for a couple of days :downs:

code:
public Butt Foo(long id)
{
    return Foo(id);
}

public Butt Foo(long id, IButt butt = null)
{
    // do stuff
    return someButt;
}

Please tell me that the horror is that you didn't realize why you were getting a stack overflow, not that that actually works.

FamDav
Mar 29, 2008

yaoi prophet posted:

Please tell me that the horror is that you didn't realize why you were getting a stack overflow, not that that actually works.

I'm surprised it even compiles. In c++ it would throw an ambiguity error.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
Yep the C# compiler accepted it just fine. Initially there was only one signature, the first, so I didn't catch the mistake brewing when I refactored it to add the second form.

npe
Oct 15, 2004
code:
if(message.equals(null))
{
  throw new Exception("The Message was NULL");
}
:downs: defensive programming

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

npe posted:

code:
if(message.equals(null))
{
  throw new Exception("The Message was NULL");
}
:downs: defensive programming

That's all kinds of retarded.

npe
Oct 15, 2004
Well while I'm at it, I should post this one that's in literally every method I can see:

code:
catch (Exception e)
{
  throw new Exception(e);
}
Somewhere in here is the business logic I need to preserve before I torch this entire project, if I can only avoid blinding myself from the insanity for long enough to find it...

hepatizon
Oct 27, 2010

npe posted:

code:
if(message.equals(null))
{
  throw new Exception("The Message was NULL");
}
:downs: defensive programming

Is this just about using Exception instead of NullPointerException, or is there an additional horror?

Opinion Haver
Apr 9, 2007

If message is null, message.equals(null) will throw a null pointer exception.

xf86enodev
Mar 27, 2010

dis catte!

hepatizon posted:

Is this just about using Exception instead of NullPointerException, or is there an additional horror?

I'm not an expert but this looks like a NullPointerException to me? Unless C#'s null has an equals method. Which it should. It's almost 2012 dammit.

efb of course

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

xf86enodev posted:

I'm not an expert but this looks like a NullPointerException to me? Unless C#'s null has an equals method. Which it should. It's almost 2012 dammit.
That's not C#, if it was it would be Equals.

ninjeff
Jan 19, 2004

Aleksei Vasiliev posted:

That's not C#, if it was it would be Equals.

That's not C#, if it was it would be ==.

ymgve
Jan 2, 2004


:dukedog:
Offensive Clock
I just had the pleasure of helping someone getting Blowfish to work through PHP's crypt() function.

There's just so much I love about this:
- The way the documentation forgets to mention that you need to place a $ character at the end of the salted string when using Blowfish
- An example of using Blowfish in the comments that uses a salt that's beyond the Blowfish password spec
- The way it happily trucks on without any error messages or feedback when you send in a malformed salt ("Let's just fall back to DES, that's secure, right?")
- The complete lie in the documentation about the return value ("Returns the hashed string or a string that is shorter than 13 characters and is guaranteed to differ from the salt on failure." - No it doesn't, it just returns a DES hash (Which is 13 characters in size))

I'm not sure if it's mostly the underlying crypt() function's fault, or PHP, but it's a coding horror any way.

Zombywuf
Mar 29, 2008

ymgve posted:

I just had the pleasure of helping someone getting Blowfish to work through PHP's crypt() function.

There's just so much I love about this:
- The way the documentation forgets to mention that you need to place a $ character at the end of the salted string when using Blowfish
- An example of using Blowfish in the comments that uses a salt that's beyond the Blowfish password spec
- The way it happily trucks on without any error messages or feedback when you send in a malformed salt ("Let's just fall back to DES, that's secure, right?")
- The complete lie in the documentation about the return value ("Returns the hashed string or a string that is shorter than 13 characters and is guaranteed to differ from the salt on failure." - No it doesn't, it just returns a DES hash (Which is 13 characters in size))

I'm not sure if it's mostly the underlying crypt() function's fault, or PHP, but it's a coding horror any way.

Doesn't gen_salt solve all these problems for you?


Also, found this on reddit, optimisation on modern CPUs is a horror unto itself http://stackoverflow.com/questions/8547778/why-is-one-loop-so-much-slower-than-two-loops

pigdog
Apr 23, 2004

by Smythe

Zombywuf posted:

Also, found this on reddit, optimisation on modern CPUs is a horror unto itself http://stackoverflow.com/questions/8547778/why-is-one-loop-so-much-slower-than-two-loops

:psyduck:

Reminds me of one of the first BASIC programs I wrote as a 11-year-old. I can't even remember the syntax of the language, but the gist of it was like this:

code:
10 initialize_graphics
20 x = rand(screen_width)
30 y = rand(screen_height)
40 color = rand(number_of_colors)
50 putpixel(x, y, color)
60 GOTO 20
Can you guess what the output was?




It should have "snowed" randomly colored pixels, but in reality the pixels developed on the screen clear, diagonal, bands of color like this: "///". It totally boggled my teacher's mind. :smug:

hepatizon
Oct 27, 2010

yaoi prophet posted:

If message is null, message.equals(null) will throw a null pointer exception.

Oh ouch. I'll probably be doing poo poo like that if I ever go back to Java from Ruby.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Zombywuf posted:

Also, found this on reddit, optimisation on modern CPUs is a horror unto itself http://stackoverflow.com/questions/8547778/why-is-one-loop-so-much-slower-than-two-loops

That depends on your definition of modern... you'd probably get similar behavior going back to the Pentium Pro (the first OOO superscalar x86 chip).

Sedro
Dec 31, 2008

ninjeff posted:

That's not C#, if it was it would be ==.

It should have been == in Java too. Or maybe it is C#, and equals is an extension method
code:
public static bool equals(this object obj, object other)
{
    return Equals(obj, other);
}

Zombywuf
Mar 29, 2008

Zhentar posted:

That depends on your definition of modern... you'd probably get similar behavior going back to the Pentium Pro (the first OOO superscalar x86 chip).

CPU prediction logic has got more complex since then, which is what that problem seems to be about.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Sedro posted:

It should have been == in Java too. Or maybe it is C#, and equals is an extension method
code:

public static bool equals(this object obj, object other)
{
    return Equals(obj, other);
}
If it's an extension method then it won't throw on null - you can call extension methods on null. This is probably the horror.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Dessert Rose posted:

This is probably the horror.

If by "horror" you mean "awesome", yes.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Dessert Rose posted:

If it's an extension method then it won't throw on null - you can call extension methods on null. This is probably the horror.

You say this like that statement only contained one horror. The horror density of that little snippet is quite high.

Scaevolus
Apr 16, 2007

Zombywuf posted:

CPU prediction logic has got more complex since then, which is what that problem seems to be about.

No, the problem is about cache aliasing.

Zakath
Mar 22, 2001

i barely GNU her! posted:

Yep the C# compiler accepted it just fine. Initially there was only one signature, the first, so I didn't catch the mistake brewing when I refactored it to add the second form.
Just like today C# compiled this:

code:
private void SomeFunc()
{
    someNumber =+ someOtherNumber;
}
I just couldn't understand why the value of someNumber wasn't increasing...

Null Pointer
May 20, 2004

Oh no!

Scaevolus posted:

No, the problem is about cache aliasing.

Well, the first problem is conflict misses in the cache. The graphs they created show capacity misses, which is an unrelated problem.

The real horror is microbenchmarking without taking at least one computer architecture course.

quote:

Every low-level performance related question on StackOverflow should be required to provide MFLOPS information for the whole range of cache relevant data sizes!

Zombywuf
Mar 29, 2008

Null Pointer posted:

Well, the first problem is conflict misses in the cache. The graphs they created show capacity misses, which is an unrelated problem.

The real horror is microbenchmarking without taking at least one computer architecture course.

To be fair the compiler designer is supposed to have done that for you.

npe
Oct 15, 2004

Dessert Rose posted:

If it's an extension method then it won't throw on null - you can call extension methods on null. This is probably the horror.

You guys are way overthinking this. It's java, it's broken, and this paradigm is everywhere you look in this codebase (complete with matching catch (Exception e) { throw new Exception(e); } every time).

Adbot
ADBOT LOVES YOU

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
catch (Exception e) { throw e; } just isn't dumb enough.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply