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
Jonnty
Aug 2, 2007

The enemy has become a flaming star!

UberJumper posted:

:psyduck:

code:
_CREATE_GP_DEFS = {
  '9.0' : (lambda x = (lambda : __import__('win32com.client')) :
    win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")),
  '9.1' : (lambda x = (lambda : __import__('win32com.client')) :
    win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")),
  '9.2' : (lambda x = (lambda : __import__('arcgisscripting')) :
    arcgisscripting.create()),
  '9.3' : (lambda x = (lambda : __import__('arcgisscripting')) :
    arcgisscripting.create(9.3))
}

Has he devised some sort of weird parallel of currying that only works in the imperative world?

Adbot
ADBOT LOVES YOU

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"

UberJumper posted:

:psyduck:

code:
_CREATE_GP_DEFS = {
  '9.0' : (lambda x = (lambda : __import__('win32com.client')) :
    win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")),
  '9.1' : (lambda x = (lambda : __import__('win32com.client')) :
    win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")),
  '9.2' : (lambda x = (lambda : __import__('arcgisscripting')) :
    arcgisscripting.create()),
  '9.3' : (lambda x = (lambda : __import__('arcgisscripting')) :
    arcgisscripting.create(9.3))
}

What does this even do? The lambda parameters aren't used anywhere, so the imports are pointless.

e:

Jonnty posted:

Has he devised some sort of weird parallel of currying that only works in the imperative world?

This looks like it's supposed to simulate lazy evaluation, not currying, unless there's something really weird going on elsewhere.

TOO SCSI FOR MY CAT fucked around with this message at 06:00 on Jan 26, 2010

UberJumper
May 20, 2007
woop

Janin posted:

What does this even do? The lambda parameters aren't used anywhere, so the imports are pointless.

e:


This looks like it's supposed to simulate lazy evaluation, not currying, unless there's something really weird going on elsewhere.

Oops! I actually copied the broken one, here is the correct one that was checked in:

code:
_CREATE_GP_DEFS = {
  '9.0' : (lambda x = (lambda : __import__('win32com.client')) :
    (x()).Dispatch("esriGeoprocessing.GpDispatch.1")),
  '9.1' : (lambda x = (lambda : __import__('win32com.client')) :
    (x()).Dispatch("esriGeoprocessing.GpDispatch.1")),
  '9.2' : (lambda x = (lambda : __import__('arcgisscripting')) :
    (x()).create()),
  '9.3' : (lambda x = (lambda : __import__('arcgisscripting')) :
    (x()).create(9.3))
}
I only noticed this, because i am partially using some common modules, and saw that. His argument was "I dont want to create 2 line functions!"

It works.. i kinda like it but... :psyduck:

UberJumper fucked around with this message at 06:26 on Jan 26, 2010

king_kilr
May 25, 2007
WTF does he create the parameter, how is __import__("poo poo").create() any worse than that disaster.

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.
He probably thinks it only gets evaluated once.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

UberJumper posted:

I only noticed this, because i am partially using some common modules, and saw that. His argument was "I dont want to create 2 line functions!"

I bet this guy's mind will be blown when he figures out how return values work.

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"

UberJumper posted:

Oops! I actually copied the broken one, here is the correct one that was checked in:

code:
_CREATE_GP_DEFS = {
  '9.0' : (lambda x = (lambda : __import__('win32com.client')) :
    (x()).Dispatch("esriGeoprocessing.GpDispatch.1")),
  '9.1' : (lambda x = (lambda : __import__('win32com.client')) :
    (x()).Dispatch("esriGeoprocessing.GpDispatch.1")),
  '9.2' : (lambda x = (lambda : __import__('arcgisscripting')) :
    (x()).create()),
  '9.3' : (lambda x = (lambda : __import__('arcgisscripting')) :
    (x()).create(9.3))
}
I only noticed this, because i am partially using some common modules, and saw that. His argument was "I dont want to create 2 line functions!"

It works.. i kinda like it but... :psyduck:

There ought to be a competency test and license requirement for using lambda...

code:
with_mod = lambda name, f: lambda: f(__import__(name))

_CREATE_GP_DEFS = {
  '9.0': with_mod('win32com.client', lambda x: x.Dispatch("esriGeoprocessing.GpDispatch.1")),
  '9.2': with_mod('arcgisscripting', lambda x: x.create())
  # etc
}

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Janin posted:

There ought to be a competency test and license requirement for using lambda...

Pretty sure this is sufficient:
code:
_CREATE_GP_DEFS = {
  '9.0' : lambda: __import__('win32com.client').Dispatch("esriGeoprocessing.GpDispatch.1")),
  # ...
}
(EDIT: oops)

Avenging Dentist fucked around with this message at 08:09 on Jan 26, 2010

Zombywuf
Mar 29, 2008

This is why Python can't have nice things.

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

Zombywuf posted:

This is why Python can't have nice things.

I think this code is essentially the argument people use against Java getting closures. It's pretty convincing, I have to admit.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
If someone being dumb is a convincing argument to you, then this thread is an argument against any language getting any feature.

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

Mustach posted:

If someone being dumb is a convincing argument to you, then this thread is an argument against any language getting any feature.

Eh, that's going a bit far. I definitely think the population of programmers that "write" Java for a living contains an abundant amount of people that would "[be] dumb" with closures. Looks like Python is getting there too. Popularity brings morons. In droves.

Zombywuf
Mar 29, 2008

TRex EaterofCars posted:

Eh, that's going a bit far. I definitely think the population of programmers that "write" Java for a living contains an abundant amount of people that would "[be] dumb" with closures. Looks like Python is getting there too. Popularity brings morons. In droves.

Python was deliberately created for morons^Wbeginners.

BattleMaster
Aug 14, 2000

The Python manual just says (or used to say, haven't checked in a while) that the lambda keyword is similar to the one used in functional languages. That's all. I took that to mean "if you don't know what this is you don't need to use it"

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde
The two features I dislike the most in .NET 3.5 are lambda expressions and the return of the dreaded var. Yes, I know the compiler can work it out. I'm not as smart as the compiler. If I'm looking at your code, there's a good chance there's something wrong with it. Please make my life a bit easier.

At least they gave us automatic properties to make up for it.

POKEMAN SAM
Jul 8, 2004

Milotic posted:

The two features I dislike the most in .NET 3.5 are lambda expressions and the return of the dreaded var. Yes, I know the compiler can work it out. I'm not as smart as the compiler. If I'm looking at your code, there's a good chance there's something wrong with it. Please make my life a bit easier.

At least they gave us automatic properties to make up for it.

1. Lambda expressions are amazing, especially when dealing with dispatching stuff between worker threads and the UI thread.

2. I agree, var blows. It might not be a problem if you're the one writing the code, but when I'm trying to read it...

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
What would you consider to be the pathological case for type inference? The normal auto i = map_of_vectors_of_strings_or_whatever.begin(); and var foo = new Bar::Baz<Fred>(...); stuff seems pretty unobjectionable

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Ugg boots posted:

2. I agree, var blows. It might not be a problem if you're the one writing the code, but when I'm trying to read it...

Yes, I too hate things that make generic programming easier and less verbose.

spiritual bypass
Feb 19, 2008

Grimey Drawer

Avenging Dentist posted:

Yes, I too hate things that make generic programming easier and less verbose.

PHP makes generic programming easier and less verbose...

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
PHP doesn't support generic programming at all...

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

rt4 posted:

PHP makes generic programming easier and less verbose...

Ah yes, the fallacy of division. (And perhaps more importantly, equivocation.)

Avenging Dentist fucked around with this message at 06:01 on Jan 27, 2010

Alex007
Jul 8, 2004

I know this is really minor ...

code:
  If DisplayWebToolbar then Begin
    WebViewSpeedBtn.Visible := True;
    WebAddSpeedBtn.Visible := True;
  End
  Else begin
    WebViewSpeedBtn.Visible := False;
    WebAddSpeedBtn.Visible  := False;
  end;
... but having to maintain someone else's code and finding little stupid things like these EVERYWHERE all the drat time is going to make me find the guy who wrote it and kill him. Seriously, shrink that back to two lines, and use the same case on your begin/end dammit.

jarito
Aug 26, 2003

Biscuit Hider

Avenging Dentist posted:

Yes, I too hate things that make generic programming easier and less verbose.

Right, but that's not what we are complaining about. This is:

code:
void someFunc(var a, var b, var c) 
{
    var d = a.Object.DoSomething();
    d.execute();
}
Using var where the typing information is unneeded is fine, but it gives idiots a crutch to turn C# into a weakly typed language, which it is not.

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

jarito posted:

Right, but that's not what we are complaining about. This is:

code:
void someFunc(var a, var b, var c) 
{
    var d = a.Object.DoSomething();
    d.execute();
}
Using var where the typing information is unneeded is fine, but it gives idiots a crutch to turn C# into a weakly typed language, which it is not.
You can't use var in parameters in C#...

You could use dynamic in C# 4.0, but dynamic and var are two different concepts.

edit:
And var in C# has absolutely nothing to do with weak/strong typing.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

jarito posted:

Right, but that's not what we are complaining about. This is: <insert uncompilable code in an attempt to support a fabricated complaint>
And once again, the coding horrors thread folds back in on itself.

shrughes
Oct 11, 2008

(call/cc call/cc)
Ok, listen up, folks.

var doesn't make C# weakly typed. Do you write your code like this:

code:
double distance = sqrt(square(x1 - x2) + square(y1-y2));
Or do you write it like this:

code:
double xDiff = x1 - x2;
double yDiff = y1 - y2;
double xSq = square(xDiff);
double ySq = square(yDiff);
double s = square(xSq + ySq);
double distance = sqrt(s);
Oh, let me guess: you'd write the latter.

P.S. Anybody who doesn't know their functions' return types is really a crabby dumb babby who sucks the teet of autocomplete.

Athas
Aug 6, 2007

fuck that joker

jarito posted:

Right, but that's not what we are complaining about. This is:

code:
void someFunc(var a, var b, var c) 
{
    var d = a.Object.DoSomething();
    d.execute();
}
Using var where the typing information is unneeded is fine, but it gives idiots a crutch to turn C# into a weakly typed language, which it is not.

It is you. You are the horror who codes.

By your logic, the type inference in Haskell also makes it weakly typed.

Seth Turtle
May 6, 2007

by Tiny Fistpump

jarito posted:

Using var where the typing information is unneeded is fine, but it gives idiots a crutch to turn C# into a weakly typed language, which it is not.

These guys disagree.

C# Reference posted:

Beginning in Visual C# 3.0, variables that are declared at method scope can have an implicit type var. An implicitly typed local variable is strongly typed just as if you had declared the type yourself, but the compiler determines the type.

king_kilr
May 25, 2007
The real coding horror is not knowing the difference between strong/weak typing and static/dynamic typing.

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde
The problem I have with var is that it binds to the strictest return type of a method/constructor, which tends to discourage polymorphism and hence hinder refactoring.

I can appreciate lambda expressions and extension methods speed up the initial developer's output, but it stinks for other people who look at your code.

Vanadium
Jan 8, 2005

king_kilr posted:

The real coding horror is not knowing the difference between strong/weak typing and static/dynamic typing.

var is neither weak nor dynamic. :colbert:

mr_jim
Oct 30, 2006

OUT OF THE DARK

Type inferencing is magic.

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

Milotic posted:

The problem I have with var is that it binds to the strictest return type of a method/constructor, which tends to discourage polymorphism and hence hinder refactoring.
I can somewhat understand your point about it discouraging polymorphism (although I don't agree with it), but how does it hinder refactoring?

edit:
In what way does it do either of those two things?

dwazegek fucked around with this message at 22:55 on Jan 27, 2010

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Milotic posted:

I can appreciate lambda expressions and extension methods speed up the initial developer's output, but it stinks for other people who look at your code.
I'm not even sure that this is the case - personally I find just inlining a lambda more beautiful and easier to understand than, say, the Java policy of passing in some reference to a Runnable object. :confused:

(I'm assuming we're making the definition of lambda elastic enough to include a Java-like "anonymous class" which I don't think closes over its containing block)

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog

dwazegek posted:

I can somewhat understand your point about it discouraging polymorphism (although I don't agree with it), but how does it hinder refactoring?

edit:
In what way does it do either of those two things?

I'm assuming he's talking about a scenario where a function returns MySpecialListType<string> but the caller only really wants/needs an IEnumerable<string>. Since var only exists in local scope I don't imagine it's really any trouble to fix it.

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"

Free Bees posted:

I'm assuming he's talking about a scenario where a function returns MySpecialListType<string> but the caller only really wants/needs an IEnumerable<string>. Since var only exists in local scope I don't imagine it's really any trouble to fix it.

Why does this matter? Presumably if the variable is later passed to a procedure that accepts IEnumerable, its type will be inferred to be IEnumerable, right?

zombienietzsche
Dec 9, 2003
And even if it's inferred as MySpecialListType<string> this doesn't pose a problem unless MySpecialListType doesn't implement IEnumerable

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde
It's only an issue when you start writing procedures which accept that implicitly defined variable - many code completion tools and whatnot (I think resharper will, will have to try it tomorrow), will create a method that uses the specific type, rather than something more abstract. If you explicitly declare it as an IEnumerable, it won't.

It's a fairly weak argument, and depends on your coding style/whether you use code completion stuff.

Also, I guess var causes more headaches when it comes to arrays. An array of objects is not the supertype of an array of strings (say), so I think it's best to be explicit when declaring an array.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
If a variable's (or function's return value's) type is inferred as ArrayList instead of List, users of the variable/function can write code which only works with ArrayList; thus you get implicit dependencies on some type which was meant to be purely an internal implementation detail.

In practice I doubt this is a serious concern; I find it's very rarely useful to swap implementation types without making other structural/semantic changes that require client code to be updated anyway.

Adbot
ADBOT LOVES YOU

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
Lambdas are awesome, I can't imagine why anyone would think otherwise. The alternative is the old 2.0 anonymous delegate syntax which was ugly as hell and hard to read. Unless you've been in bracket land your entire programming career, lambdas read very naturally.

var I can understand because it can make code harder to read at a glance. Yeah weakly-typed languages aren't inherently harder to read than strongly-typed languages but when you run into what looks like weak typing in the middle of strongly-typed code it forces you to put on the breaks.

Having said that its usage in limited areas (like foreach loops on some complicated enumeration or linq expression results) it does make the code more compact without sacrificing too much clarity.

dynamic scares me. Everyone who *thinks* var introduces weak-typing is gonna fuckin' love dynamic.

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