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
The Reaganomicon
Oct 14, 2010

by Lowtax

Munkeymon posted:

Show us switch statement that can deal with greater than or less than and that would be a valid alternative.

I submit, most languages can't handle this gracefully. :negative:

On a completely unrelated note, I love C#'s ?? operator.

Adbot
ADBOT LOVES YOU

spiritual bypass
Feb 19, 2008

Grimey Drawer
Hey, that sounds like a big timesaver! Then again, so did PHP when I was looking for my first job...

Opinion Haver
Apr 9, 2007

The Reaganomicon posted:

I submit, most languages can't handle this gracefully. :negative:

On a completely unrelated note, I love C#'s ?? operator.

code:
fib x | x < 2 = x
      | otherwise = fib (x-1) + fib (x-2)
:smug:

The Reaganomicon
Oct 14, 2010

by Lowtax
Functional languages need not apply, they do everything gracefully.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Munkeymon posted:

Show us switch statement that can deal with greater than or less than and that would be a valid alternative. I'm OK with what GrumpyDoctor wrote and the only problem I would have with it is that I don't trust all other programmers to understand the ternary operator well enough to not accidentally gently caress it up. Several people I work with would be totally lost, for example.

php:
<?
switch (true) {
    case 4 < 1:
        echo 'heads';
        break;
    case 5 > 9:
        echo 'shoulders';
        break;
    case 3 < 9:
        echo 'knees';
        break;
    case 4 > 1:
        echo 'toes';
        break;
    default:
        echo 'rear end';
}
?>
knees :tipshat:

Pollyzoid
Nov 2, 2010

GRUUAGH you say?

The Reaganomicon posted:

You would be the minority that likes using languages without a switch construct.

Lua is quite popular :colbert:

Although it doesn't have the ternary operator, you can still use logic short-circuiting.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

The Reaganomicon posted:

You would be the minority that likes using languages without a switch construct.
A switch statement is twice as much code to do the exact same thing and if anything is less readable.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

yaoi prophet posted:

code:
fib x | x < 2 = x
      | otherwise = fib (x-1) + fib (x-2)
:smug:

Does ML use semantic indentation like haskell or does everyone just line poo poo up because it looks better

e: also does it make sense to learn OCaml directly if I have a kinda-sorta in at a place that uses it or should i LMAH (learn me a haskell) then make the (easy? i hope) haskell->ocaml transition

The Reaganomicon
Oct 14, 2010

by Lowtax

Otto Skorzeny posted:

Does ML use semantic indentation like haskell or does everyone just line poo poo up because it looks better

White space is completely optional, afaik.

Otto Skorzeny posted:

e: also does it make sense to learn OCaml directly if I have a kinda-sorta in at a place that uses it or should i LMAH (learn me a haskell) then make the (easy? i hope) haskell->ocaml transition

Christ, just do F# or something. OCaml is dead in the water.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Of the 4 financials recruiting on my campus, 3 use ocaml and 2 use haskell, soooooooo

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender
OCaml will be easier to learn than Haskell if you are coming from a strict language background.

You should still learn both, though; Haskell is fun.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Yeah I ought to buy BONUS's book just out of principle anyways :v:

ninjeff
Jan 19, 2004

Munkeymon posted:

Show us switch statement that can deal with greater than or less than and that would be a valid alternative. I'm OK with what GrumpyDoctor wrote and the only problem I would have with it is that I don't trust all other programmers to understand the ternary operator well enough to not accidentally gently caress it up. Several people I work with would be totally lost, for example.

code:
Dim y As String
Select Case x
    Case Is < 0
        y = "less than zero"
    Case 0
        y = "zero"
    Case Is > 0
        y = "greater than zero"
End Select
What we really need to replace ternary operator chains is an inline switch like in SQL, though.

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!
I was reviewing a buddy of mine's homework for an intro CS class I convinced him to take. He was asked to get a bunch of information from a '/' delimited string and store it an array.

Since the class is taught with Java, the correct solution would have been String.split(). Instead he came up with this ugly workaround that made me laugh:

code:
Scanner scan = new Scanner(args[0]);
scan.useDelimiter("/");
ArrayList<String> list = new ArrayList<String>();

while(scan.hasNext())
  list.add(scan.next());

String[] info = new String[list.size()];

for(int i = 0; i < list.size(); i++)
  info[i] = list.get(i);

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I don't see the horror, this is a first year CS student who doesn't know the API. :colbert:

zeekner
Jul 14, 2007

quote:

Coding horrors: post the code that makes you laugh (or cry)

Eggnogium posted:

this ugly workaround that made me laugh:

Not everything in this thread has to be straight from the demented mind of an enterprise Java/PHP veteran.

I kinda like seeing the crazy ways new people solve problems, they are pretty creative (albeit in a terrible way).

zokie
Feb 13, 2006

Out of many, Sweden

MEAT TREAT posted:

I don't see the horror, this is a first year CS student who doesn't know the API. :colbert:

I remember doing my first exam in Java, with pen and paper :downs:! One of the assignments was to take an arbitrary string, make it to lower case letters and then some other poo poo. Being a new (poo poo) programmer and not knowing or being provided with documentation telling me about toLowerCase(), I made a loop to iterate through the string character by character using nested if-elses for every letter in the alphabet all the way through the string because I couldn't remember how a switch worked.

I got a 95% on that exam, with a comment about how most my code was horrible and slow as poo poo, BUT it worked :) It took the them 2 semesters to introduce us to patterns, which I think is a horror.

Zhentar
Sep 28, 2003

Brilliant Master Genius

ninjeff posted:

What we really need to replace ternary operator chains is an inline switch like in SQL, though.
code:
s y=$s(x<0:"less than zero",x=0:"zero",1:"greater than zero")
(that's SET y=$SELECT(...) for people who don't likes MUMPS abbreviations)

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.
I love that PHP broke me into this industry. I hate that breaking out of PHP will be so damned hard.

I do have SOME python experience (commercial, too), but never enough to learn the real nature of it. Same for Java.

I'm spending some of my own time re-learning these things, but without having commercial experience, I might as well be starting from scratch.

Arse.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

zokie posted:

It took the them 2 semesters to introduce us to patterns, which I think is a horror.

Teaching CS in Java and introducing patterns at all are the real horrors

The Reaganomicon
Oct 14, 2010

by Lowtax

zokie posted:

I got a 95% on that exam, with a comment about how most my code was horrible and slow as poo poo, BUT it worked :) It took the them 2 semesters to introduce us to patterns, which I think is a horror.

Our school starts with OCaml right off the bat. It's so cute watching 18 year olds come to grips with it and then ask in the most :shobon: manner why things like PHP exist. :3:

Thel
Apr 28, 2010

The Reaganomicon posted:

Our school starts with OCaml right off the bat. It's so cute watching 18 year olds come to grips with it and then ask in the most :shobon: manner why things like PHP exist. :3:

Ah the naivety of youth. Answering those questions sounds like the perfect job for someone who likes crushing dreams. :v:

Shugyousha
Sep 24, 2007
Just (s)trolling by...

Otto Skorzeny posted:

Yeah I ought to buy BONUS's book just out of principle anyways :v:

That's what I thought too. Even if I never get to use Haskell in a commercial setting, for all the fun I had reading his site I should really buy it. I was actually thinking about opening a thread for his book since he seems to be too modest to mention it...


Links:

http://oreilly.com/catalog/9781593272838/ <- Book

http://learnyouahaskell.com/ <- Site

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde
We studied Haskell as our first language at uni (it was my first time programming as well). I was so happy when we made the transition to imperative programming.

Seven years on and bits of the bible still give me trouble. I read it on the train every so often.

I'm a software developer for a bank and I'm so happy we don't do functional programming. Wouldn't mind trying aspect-oriented on a proper production app.

shrughes
Oct 11, 2008

(call/cc call/cc)

Milotic posted:

I'm a software developer for a bank and I'm so happy we don't do functional programming. Wouldn't mind trying aspect-oriented on a proper production app.

You're trolling, right? Or maybe you're just stupid.

Edit: Yes, obviously dissing functional programming and mentioning aspect-oriented programming are the best ways to troll me.

shrughes fucked around with this message at 05:04 on Mar 7, 2011

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
code:
 //World w is defined elsewhere
    
for(Body b:w.getBodies()) {
	for( Fixture f : b.getFixtureList() ) {

		Shape s=f.getShape();
		    
		if( b.getType()==BodyType.DynamicBody ){
			addToBuffer(s, mDynamicBuffer);
		} else {
			addToBuffer(s, mStaticBuffer);
		}

		int bufLen=mStaticBuffer.position()/2;
		mStaticBuffer.position(0);

		gl.glColor4f(mStaticColor[R], mStaticColor[G], mStaticColor[B], 1.0f);
		gl.glVertexPointer(2, GL10.GL_FLOAT, 0, mStaticBuffer);
		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
		gl.glDrawArrays(GL10.GL_LINES, 0, bufLen);

		bufLen=mDynamicBuffer.position()/2;
		mDynamicBuffer.position(0);

		gl.glColor4f(mDynamicColor[R], mDynamicColor[G], mDynamicColor[B], 1.0f);
		gl.glVertexPointer(2, GL10.GL_FLOAT, 0, mDynamicBuffer);
		gl.glDrawArrays(GL10.GL_LINES, 0, bufLen);
		gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); 
	}
}
My code. Box2d and OpenGl on Android.

You see, I optimized :science: the drawing (because native, i.e. OpenGl, calls are slow) by buffering all the edges of all the shapes into mDynamicBuffer and mStaticBuffer and then drawing them all with one OpenGl call.

Except I drew them one at a time anyway and redrew the latest "other kind" of object with every object. :pseudo:

The buffers are large enough to hold all the vertices of all the objects. That was their whole point.

e: Moving the OpenGl code out of the loop tripled the frame rate.

Wheany fucked around with this message at 13:07 on Mar 7, 2011

NotShadowStar
Sep 20, 2000

shrughes posted:

You're trolling, right? Or maybe you're just stupid.

Edit: Yes, obviously dissing functional programming and mentioning aspect-oriented programming are the best ways to troll me.

You sure do love calling people stupid when they don't agree with you 100%.

Some people find it easier to think in relations of objects that do things, some people find it easier to think in formulas that manipulate numbers.

White people drive like THIS, black people drive like THIS.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

NotShadowStar posted:

White people drive like THIS, black people drive like THIS.
And Asian people can't drive at all.

(php programmers === asian people)

NotShadowStar
Sep 20, 2000
Sure thing, nothing brings together disparate, warring entities like good old fashioned chink hating amirite!

tef
May 30, 2004

-> some l-system crap ->
aspect orientated programming is for when you suffer trying to implement spaghetti code in normal oo

The Reaganomicon
Oct 14, 2010

by Lowtax

NotShadowStar posted:

Some people find it easier to think in relations of objects that do things, some people find it easier to think in formulas that manipulate numbers.

im sorry about you`re brain damage

NotShadowStar
Sep 20, 2000

The Reaganomicon posted:

im sorry about you`re brain damage

:ironicat:

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

shrughes posted:

You're trolling, right? Or maybe you're just stupid.
Are you serious here or are you just really out of touch with reality

Orzo fucked around with this message at 23:08 on Mar 7, 2011

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

shrughes posted:

You're trolling, right? Or maybe you're just stupid.

Edit: Yes, obviously dissing functional programming and mentioning aspect-oriented programming are the best ways to troll me.
He's implying that Haskell isn't imperative, so yes, he is

Also, some ridiculous percentage (like 75-85%) of OCaml and Haskell programmers work in finance. It's like saying "I'm so glad I'm going to work in the games industry, so I don't have to write in C"

NotShadowStar
Sep 20, 2000

Orzo posted:

Are you serious here our are you just really out of touch with reality

That's not an exclusive or :xd:

shrughes
Oct 11, 2008

(call/cc call/cc)

Orzo posted:

Are you serious here or are you just really out of touch with reality

I am being serious. Milotic complained about how dumb he is. Which makes him seem stupid. [1] But then he seemed to rub it in by saying he wouldn't mind trying aspect-oriented programming. Which makes it seem like he's really just trolling.

That's how I read it.

[1] Actually, this doesn't make him seem stupid, since people who consider themselves stupid generally aren't that stupid. But then he mentioned aspect-oriented programming.

Edit: also if you're exhibiting that sort of post-traumatic stress about functional programming, you have to be trolling or you have to be stupid. That's just the way objective reality is.

Edit II: Fine, I'll concede that if it's theoretically possible for somebody to be smart and have problems with functional programming, then it's possible that Milotic is not stupid. Just ignorant.

shrughes fucked around with this message at 01:54 on Mar 8, 2011

Contra Duck
Nov 4, 2004

#1 DAD

Janin posted:

He's implying that Haskell isn't imperative, so yes, he is

Also, some ridiculous percentage (like 75-85%) of OCaml and Haskell programmers work in finance. It's like saying "I'm so glad I'm going to work in the games industry, so I don't have to write in C"

But what percentage of developers in finance work in Haskell or OCaml?

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde

shrughes posted:

I am being serious. Milotic complained about how dumb he is. Which makes him seem stupid. [1] But then he seemed to rub it in by saying he wouldn't mind trying aspect-oriented programming. Which makes it seem like he's really just trolling.

That's how I read it.

[1] Actually, this doesn't make him seem stupid, since people who consider themselves stupid generally aren't that stupid. But then he mentioned aspect-oriented programming.

I'm not a good functional programmer, but I'm a good object oriented programmer. I understand the basics of FP, but the part of the course where we had to write a maze-solving algorithm in it was not my finest hour.

I've worked with aspect oriented programming in the past, but never on a production system. I can see it being useful to solve spaghetti code, or a specific instance where you have a model but the view is composed of several user controls.

Janin posted:

He's implying that Haskell isn't imperative, so yes, he is

Also, some ridiculous percentage (like 75-85%) of OCaml and Haskell programmers work in finance. It's like saying "I'm so glad I'm going to work in the games industry, so I don't have to write in C"

For your first point, I believe this thread has had that discussion in the past. I am sure you can do wonderful things with monads, but Haskell is not a conventional imperative language. Page 325, second edition of "Introduction to FP using Haskell" says:

quote:

In a sense, monadic style enables one to write functional programs that mimic state-based computation,...that mimic imperative programs, those programs constructed in imperative languages such as Pascal and C

For your second point, the vast majority of developers in the finance sector don't do either Haskell or OCaml. That wasn't my point. My point was more like "I work in the games industry, but I'm happy I don't do Silverlight based mobile apps".

Haskell is a niche. An incredibly lucrative niche, but a niche.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

Milotic posted:

For your first point, I believe this thread has had that discussion in the past. I am sure you can do wonderful things with monads, but Haskell is not a conventional imperative language. Page 325, second edition of "Introduction to FP using Haskell" says:

For your second point, the vast majority of developers in the finance sector don't do either Haskell or OCaml. That wasn't my point. My point was more like "I work in the games industry, but I'm happy I don't do Silverlight based mobile apps".

Haskell is a niche. An incredibly lucrative niche, but a niche.
Imperative/declarative is a matter of syntax. Haskell supports both declarative (let-notation) and imperative (do-notation).

Functional/stateful is a matter of execution model. Functional languages are based on the lambda calculus, whereas stateful languages are based on the Turing machine. Even when using it for imperative code (eg, systems programming), Haskell is a functional language.

Any tutorial/introduction/book about Haskell that doesn't explicitly mention using it as an imperative language (as a replacement for C) is terribly incomplete. For example, I've never even heard of the book you linked as a "bible", and if it was published in 1998(!!) then it's basically worthless for all intents and purposes. I mean, gently caress, that means it was written before Haskell had modules! Throw that poo poo out.

If by "finance sector" you mean anyone employed by any financial company, then sure -- most of them are probably using something like COBOL or Java. But if you mean people actually involved in writing finance-related code, almost all of it will be in some sort of functional language. Whether that's ML, OCaml, Matlab, R, Haskell, doesn't really matter.

Adbot
ADBOT LOVES YOU

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Yeah, I did a full year of Miranda in university (good lord so old, don't even think it's in use any more) to get my introduction to FP. I'd already taught myself Turbo Pascal and ANSI C at that point (oh man it gets even older) in high school, and man did I hate Miranda at first. However after the first quarter or so it was pretty neat how it made you think differently. I think I "got it" when I had to make a roman numeral parser/displayer and realized that the old way of planning it out was just plain wrong.

That said, I look at the programming I do now, day in and day out, and just don't see how FP would do it. I can bet that the stuff it can do well is pretty awesome (which, I'm guessing would involve pure math and analytics), but tweaking web layouts, database massaging, file parsing, etc. doesn't seem to fit the bill.

Which leads me to a question; has anyone been exposed to both Miranda and Haskell and can tell me how similar they are? Wikipedia says 'very similar' but doesn't really give specifics, but I'd be curious to know how much changeover would be involved if I wanted to pick up Haskell based solely on my Miranda exposure (I got to be pretty good at it at the end).

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