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
Zlodo
Nov 25, 2006

Abandon posted:

we should do a survey of which languages have "lambdas" where you can do anything at all with the lambda besides execute it
like say determine whether or not some I/O operation will successfully run

if you can't, then a lambda is a glorified function pointer

if you need to do more things than just execute it why not pass an object instead

Adbot
ADBOT LOVES YOU

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

Nomnom Cookie posted:

java 8 adds function pointers too

loving finally

Abandon
Nov 23, 2006

Zlodo posted:

if you need to do more things than just execute it why not pass an object instead

thats kind of the whole point of lambdas, theyre meant to be code as a first class object in the language

Nomnom Cookie
Aug 30, 2009



Otto Skorzeny posted:

loving finally

its actually sugar for anonymous inner classes :ssh:

MononcQc
May 29, 2007

Abandon posted:

we should do a survey of which languages have "lambdas" where you can do anything at all with the lambda besides execute it
like say determine whether or not some I/O operation will successfully run

if you can't, then a lambda is a glorified function pointer

a function pointer and its attached surrounding environment at declaration time, i.e. closures.

The correct argument is that closures are glorified objects, and that objects are glorified closures. Function pointers are not part of it, because they don't manage to carry contextual state around.

MononcQc
May 29, 2007

quote:

The venerable master Qc Na was walking with his student, Anton. Hoping to prompt the master into a discussion, Anton said "Master, I have heard that objects are a very good thing - is this true?" Qc Na looked pityingly at his student and replied, "Foolish pupil - objects are merely a poor man's closures."

Chastised, Anton took his leave from his master and returned to his cell, intent on studying closures. He carefully read the entire "Lambda: The Ultimate..." series of papers and its cousins, and implemented a small
Scheme interpreter with a closure-based object system. He learned much, and looked forward to informing his master of his progress.

On his next walk with Qc Na, Anton attempted to impress his master by saying "Master, I have diligently studied the matter, and now understand that objects are truly a poor man's closures." Qc Na responded by hitting Anton with his stick, saying "When will you learn? Closures are a poor man's object."

At that moment, Anton became enlightened.

Plastic Snake
Mar 2, 2005
For Halloween or scaring people.

Shaggar posted:

like i'd rather have c# style properties in java than lamdbadas

this a million times. I think lambdas are actually useful but c# properties own bones compared to The Java Way

Sapozhnik
Jan 2, 2005

Nap Ghost
I declare Java classes consisting of nothing but public fields all the time, get at me

Notorious b.s.d.
Jan 25, 2003

by Reene

Suspicious Dish posted:

I work with a lot of people who really love Vala. It's not a terrible language, and it actually has some pretty awesome features such as method bodies in interfaces. My main experience with it is working with libraries that are written in Vala, and they usually expose void* everywhere as their interface.

The only other thing is that debugging with gdb is abnormally hard because you have to debug all these _tmp21 = foo(); statements that are hard to pick out the original source line. I've heard that they actually put comments for every source line, so maybe it isn't too bad now.

If it's a just toy project or app, maybe you'll like it.

vala shouldn't even exist

the gnome people are impossible to work with. first they had gobject, which was an attempt to graft OO onto C without any compiler changes or whackadoo crap. it was frustrating to read/write, but it worked pretty good

then they had java-gnome. the bindings were high quality, it was documented and fully OO. but java's open source license wasn't open open source enough. so its use was officially discouraged.

then they had a wonderful and actually mostly-documented set of C# bindings for use with mono, but mono was suposedly dangerous because microsoft and novell were flirting at the time and people kept talking lawsuits. so people started rewriting existing, working C# applications in buggy C or C++ just to get off mono

so they went back to gobject and made a language out of it: vala. it's a half-baked bucket of crap that "compiles" to C+gobject code, which then has to be compiled. with all accompanying joy in debugging. also now gobject has a ton of poo poo that has to be generated by parsing C code and ugh please just die

Shaggar
Apr 26, 2006

Mr Dog posted:

I declare Java classes consisting of nothing but public fields all the time, get at me

this triggers me but I've started doing it anyways cause I've been spending more time in c# and every time I go back to java getters/setters look so dumb

Posting Principle
Dec 10, 2011

by Ralp

Mr Dog posted:

I declare Java classes consisting of nothing but public fields all the time, get at me

reminder that awt is irrevocably slow because someone made this decision and they have to live with it for ever

Opinion Haver
Apr 9, 2007

something i'm curious about: in java or c# or whatever, do lambdas like lambda x: x.foo() have a sensible type? my first guess would be no because you can't even express the notion that 'x has a method named foo' in the type system. does scala let you do this? the only languages i have experience with with real lambdas are python which just has a generic function type and haskell which isn't OO (unless you do something super wacky with fclabels/lens/whatever)

Notorious b.s.d.
Jan 25, 2003

by Reene

Mr Dog posted:

I declare Java classes consisting of nothing but public fields all the time, get at me

uhoh your implementation is showing!

Notorious b.s.d.
Jan 25, 2003

by Reene

Opinion Haver posted:

something i'm curious about : in java or c# or whatever, do lambdas like lambda x: x.foo() have a sensible type? my first guess would be no because you can't even express the notion that 'x has a method named foo' in the type system. does scala let you do this? the only languages i have experience with with real lambdas are python which just has a generic function type and haskell which isn't OO (unless you do something super wacky with fclabels/lens/whatever)

in scala function types are distinguished by their signature, so your lambda would have to take a specific "x" as an argument in its signature. if the type of x is just "a thing that has a foo() method" you would create a trait for "fooable" and the signature would look like "(fooable) -> Unit"

the story for java is much the same.

static type checking is static. type inference and sane collections libraries and lambdas make static type checking more pleasant and powerful, but it's still static.

edit: bonus option in scala that doesn't work as naturally in java -- you can use pattern matching to handle a lot of specific types for x on the fly, and this is routinely done. then the signature is "(AnyRef) -> Unit" and the type is resolved at runtime in the pattern match

Notorious b.s.d. fucked around with this message at 16:56 on Oct 28, 2013

Vanadium
Jan 8, 2005

Opinion Haver posted:

something i'm curious about : in java or c# or whatever, do lambdas like lambda x: x.foo() have a sensible type? my first guess would be no because you can't even express the notion that 'x has a method named foo' in the type system. does scala let you do this? the only languages i have experience with with real lambdas are python which just has a generic function type and haskell which isn't OO (unless you do something super wacky with fclabels/lens/whatever)

From what I can tell from 30 seconds of playing around with C#, x => x.foo() has a halfassed type and you pretty much can't do anything with that expression except use it in a context that lets the compiler infer an SomeBoringOldType => AnotherBoringOldType type.

foo.cs(3,5): error CS0815: An implicitly typed local variable declaration cannot be initialized with `anonymous method'

foo.cs(3,28): error CS0023: The `.' operator cannot be applied to operand of type `anonymous method'

foo.cs(8,5): error CS0411: The type arguments for method `Foo.f<T>(T)' cannot be inferred from the usage. Try specifying the type arguments explicitly

Notorious b.s.d.
Jan 25, 2003

by Reene

Vanadium posted:

From what I can tell from 30 seconds of playing around with C#, x => x.foo() has a halfassed type and you pretty much can't do anything with that expression except use it in a context that lets the compiler infer an SomeBoringOldType => AnotherBoringOldType type.

foo.cs(3,5): error CS0815: An implicitly typed local variable declaration cannot be initialized with `anonymous method'

foo.cs(3,28): error CS0023: The `.' operator cannot be applied to operand of type `anonymous method'

foo.cs(8,5): error CS0411: The type arguments for method `Foo.f<T>(T)' cannot be inferred from the usage. Try specifying the type arguments explicitly

it's not a halfassed type, it's just a type that gets inferred

lambdas are just syntactic sugar where the compiler infers the type for you. the type still has to be resolveable. there are no variables running around with duck-typing applied, it just feels that way when type inference works well

Shaggar
Apr 26, 2006
the way it works in c# is right altho sometimes in razor there are no types on the thing you're dealing with so you're flying blind calling any methods on the thing and you have to pray it works at runtime. I imagine that's what it feels like to do a p-lang.

JewKiller 3000
Nov 28, 2006

by Lowtax
in ocaml you can write that function. using the repl:

# fun x -> x#foo;;
- : < foo : 'a; .. > -> 'a = <fun>

the type reads: take an object with a method foo that returns 'a, and maybe some other methods too that we don't care about, and return type 'a. we get a type variable 'a (any type) because there's nothing in the function to constrain the type further. if i said x#foo + 1 then we'd have 'a = int.

it works kinda like duck typing, but statically, and with type inference! the implementation of this is based on row types :getin:

JewKiller 3000 fucked around with this message at 17:15 on Oct 28, 2013

Posting Principle
Dec 10, 2011

by Ralp
oops

Zlodo
Nov 25, 2006
[]( auto&& foo ){ return foo.x(); }

c++14 :getin:

Abandon
Nov 23, 2006
seems like they really missed a chance in java to have proper features that support the language in the virtual machine
like imagine something like const except it really means "this is immutable" and the runtime can prove that things are invariant and optimise stuff really well and all the getters and setters can gently caress off
i mean they already have a fancy managed reference type instead of a pointer into some abstract machines flat address space so why not capitalise on that
instead of make a language that barely does any more than C

havelock
Jan 20, 2004

IGNORE ME
Soiled Meat

Opinion Haver posted:

something i'm curious about : in java or c# or whatever, do lambdas like lambda x: x.foo() have a sensible type? my first guess would be no because you can't even express the notion that 'x has a method named foo' in the type system. does scala let you do this? the only languages i have experience with with real lambdas are python which just has a generic function type and haskell which isn't OO (unless you do something super wacky with fclabels/lens/whatever)

Yes, they do.
Func<WhateverTypeXIs, WhateverTypeFooReturns>
i.e., WhateverTypeXIs -> WhateverTypeFooReturns

(assuming you've declared this in a context where the type of x can be inferred). If not, you'll have to explicitly specify the type (like (ISomeInterfaceWithFoo x) => x.foo()), but yes they have sensible types that are in line with how functional languages type functions.

Posting Principle
Dec 10, 2011

by Ralp

JewKiller 3000 posted:

it works kinda like duck typing, but statically, and with type inference! the implementation of this is based on row types :getin:

code:
template <typename T>
auto do_a_foo(T t) -> decltype(t.foo()) {
	return t.foo();
}
:getin:

havelock
Jan 20, 2004

IGNORE ME
Soiled Meat

JewKiller 3000 posted:

in ocaml you can write that function. using the repl:

# fun x -> x#foo;;
- : < foo : 'a; .. > -> 'a = <fun>

the type reads: take an object with a method foo that returns 'a, and maybe some other methods too that we don't care about, and return type 'a. we get a type variable 'a (any type) because there's nothing in the function to constrain the type further. if i said x#foo + 1 then we'd have 'a = int.

it works kinda like duck typing, but statically, and with type inference! the implementation of this is based on row types :getin:

This is the only meaningful way (that I've found) that F# diverges from OCaml (nominal vs structural subtyping), I'm sure because the CLR is nominally typed.

Sapozhnik
Jan 2, 2005

Nap Ghost

Notorious b.s.d. posted:

vala shouldn't even exist

the gnome people are impossible to work with. first they had gobject, which was an attempt to graft OO onto C without any compiler changes or whackadoo crap. it was frustrating to read/write, but it worked pretty good

then they had java-gnome. the bindings were high quality, it was documented and fully OO. but java's open source license wasn't open open source enough. so its use was officially discouraged.

then they had a wonderful and actually mostly-documented set of C# bindings for use with mono, but mono was suposedly dangerous because microsoft and novell were flirting at the time and people kept talking lawsuits. so people started rewriting existing, working C# applications in buggy C or C++ just to get off mono

so they went back to gobject and made a language out of it: vala. it's a half-baked bucket of crap that "compiles" to C+gobject code, which then has to be compiled. with all accompanying joy in debugging. also now gobject has a ton of poo poo that has to be generated by parsing C code and ugh please just die

Building a desktop environment on top of Java or C# is loving stupid, the politics are just coincidental.

They are entire Qt-like universes in their own right, so have fun churning out mountains of boilerplate converting back and forth between java.util.List or System.Collections.IList objects or w/e and the native collection types used by the system frameworks. Same issue if you want to interface with GStreamer or any other such native API. Mountains of loving boilerplate so you're going to have to hope that whoever does the tedious shitwork of keeping your C#/Java bindings up to date has a binding for the exact API that you want to use and it's been tested and shown to work.

GObject still exists, there's still C-side boilerplate you have to write if you're programming for GObject in C, but you do that once and then dynamic languages can dynamically bind to it using GObject introspection, which is probably a whole lot better than the hosed up impedance mismatch resulting from trying to build a bridge to Qt's C++98 with string-identified signals and slots island of merry japes.

More than using GObject as its type system, Vala uses GLib as its standard library (ish, there's also a Vala generic containers library called Gee) so you're not trying to collide the Java universe with the GNOME universe. It gives you most of the high-level stuff that C# gives you, except that you have to manage reference cycles yourself, and interfacing with native-code GObject libraries is very easy because Vala itself compiles to native code.

It's a large part of why the official "default" language for GNOME is now JavaScript. JS sucks but at least it's just a programming language as opposed to a programming language with a gigantic compulsory standard library attached to it that duplicates a large chunk of the Gtk/GLib stack.

JewKiller 3000
Nov 28, 2006

by Lowtax

Mr Dog posted:

It's a large part of why the official "default" language for GNOME is now JavaScript. JS sucks but at least it's just a programming language as opposed to a programming language with a gigantic compulsory standard library attached to it that duplicates a large chunk of the Gtk/GLib stack.

aren't the DOM and other browser APIs exactly that standard library for javascript? if you're using js outside of the browser, you're doing it wrong

Zlodo
Nov 25, 2006

Mr Dog posted:

Building anything on top of gtk/glib is loving stupid

reminder: gnome only exists in the first place bc kde wasnt "free enough". then on top of that they decided to use c

:rms2:

Abandon
Nov 23, 2006
i was going to post "countdown until someone makes a loving javascript machine" but

http://tessel.io

Suspicious Dish
Sep 24, 2011

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

Mr Dog posted:

Building a desktop environment on top of Java or C# is loving stupid, the politics are just coincidental.

They are entire Qt-like universes in their own right, so have fun churning out mountains of boilerplate converting back and forth between java.util.List or System.Collections.IList objects or w/e and the native collection types used by the system frameworks. Same issue if you want to interface with GStreamer or any other such native API. Mountains of loving boilerplate so you're going to have to hope that whoever does the tedious shitwork of keeping your C#/Java bindings up to date has a binding for the exact API that you want to use and it's been tested and shown to work.

GObject still exists, there's still C-side boilerplate you have to write if you're programming for GObject in C, but you do that once and then dynamic languages can dynamically bind to it using GObject introspection, which is probably a whole lot better than the hosed up impedance mismatch resulting from trying to build a bridge to Qt's C++98 with string-identified signals and slots island of merry japes.

More than using GObject as its type system, Vala uses GLib as its standard library (ish, there's also a Vala generic containers library called Gee) so you're not trying to collide the Java universe with the GNOME universe. It gives you most of the high-level stuff that C# gives you, except that you have to manage reference cycles yourself, and interfacing with native-code GObject libraries is very easy because Vala itself compiles to native code.

It's a large part of why the official "default" language for GNOME is now JavaScript. JS sucks but at least it's just a programming language as opposed to a programming language with a gigantic compulsory standard library attached to it that duplicates a large chunk of the Gtk/GLib stack.

Who are you and why do you know so much about GNOME?

(Also, we're fixing a lot of the stupid boilerplate very soon)

PleasingFungus
Oct 10, 2012
idiot asshole bitch who should fuck off
Just found this interesting article about PL history linked from Ryan North's blog.

quote:

Over and over again as I’ve dredged through this stuff, I kept finding programming constructs, ideas and approaches we call part of “modern” programming if we attempt them at all, sitting abandoned in 45-year-old demo code for dead languages. And to be clear: that was always a choice. Over and over again tools meant to make it easier for humans to approach big problems are discarded in favor of tools that are easier to teach to computers, and that decision is described as an inevitability.

I don't actually agree with the article - it has a nasty tendency to go looking for facts that support its conclusion, find the opposite, and then blithely continue on claiming it was right on a technicality. (E.g., the yacht racing.)

Probably worth reading only to argue with it, though.

PleasingFungus fucked around with this message at 17:40 on Oct 28, 2013

Sapozhnik
Jan 2, 2005

Nap Ghost
Somebody who spends too much time reading LWN and half of what I just wrote is probably wrong anyway.

I don't work on GNOME in any capacity, I just like the ideas behind it, even if the implementation apparently leaves a lot to be desired from an application developer's perspective.

Suspicious Dish
Sep 24, 2011

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

Mr Dog posted:

Somebody who spends too much time reading LWN and half of what I just wrote is probably wrong anyway.

I don't work on GNOME in any capacity, I just like the ideas behind it, even if the implementation apparently leaves a lot to be desired from an application developer's perspective.

It was all correct. Do you have any feedback for us for app development?

Sapozhnik
Jan 2, 2005

Nap Ghost
See above. I don't actually code anything GNOME-related. I'm planning to do something vaguely related sometime soon-ish, but what's the fun in doing something you enjoy when you can procrastinate on doing something you don't?

keep doing what you guys are doing, I guess. Not everybody is a hater. I do hope GNOME re-finds some relevance in the future, because I don't think it entirely deserves the bad rap it's getting these days.

Suspicious Dish
Sep 24, 2011

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

Notorious b.s.d. posted:

vala shouldn't even exist

the gnome people are impossible to work with. first they had gobject, which was an attempt to graft OO onto C without any compiler changes or whackadoo crap. it was frustrating to read/write, but it worked pretty good

then they had java-gnome. the bindings were high quality, it was documented and fully OO. but java's open source license wasn't open open source enough. so its use was officially discouraged.

then they had a wonderful and actually mostly-documented set of C# bindings for use with mono, but mono was suposedly dangerous because microsoft and novell were flirting at the time and people kept talking lawsuits. so people started rewriting existing, working C# applications in buggy C or C++ just to get off mono

so they went back to gobject and made a language out of it: vala. it's a half-baked bucket of crap that "compiles" to C+gobject code, which then has to be compiled. with all accompanying joy in debugging. also now gobject has a ton of poo poo that has to be generated by parsing C code and ugh please just die

vala is not officially endorsed by gnome or anything like that. it was some guy's way to experiment with language design and it sort of became a thing that was pretty popular. some gnome people like it, some don't. i personally am not a fan.

gobject-introspection is basically an automatic java-gnome / mono bindings generator, and java-gnome / mono now use it, along with pygobject (the replacement for pygtk) and gjs (the gnome/javascript hookup). it parses c code because the free software tools for extracting meaningful data from c are garbage. it also takes a bunch of annotations to give higher-level semantics to your c code.

Zlodo
Nov 25, 2006
"C is just fine guys"

*spend ten years frantically making bindings for and trying every language under the sun as replacement*

lol gnome

rsjr
Nov 2, 2002

yay for protoss being so simple that retards can win with it
i wanna do some web dev in the best language (java) should i use play or is there something better

Suspicious Dish
Sep 24, 2011

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

Zlodo posted:

"C is just fine guys"

*spend ten years frantically making bindings for and trying every language under the sun as replacement*

lol gnome

hey if people want to do that we ain't gonna stop them. i write c because it's just fine.

yes you are correct that gnome not at all consistent in its technologies but its a project from like 500 people and 50 companies. all of them are engineers that all have spergy opinions on languages.

we are trying to fix that but it's going to take a while. sheesh.

Abandon
Nov 23, 2006

rsjr posted:

i wanna do some web dev in the best language (java) should i use play or is there something better

stop trolling

Shaggar
Apr 26, 2006

rsjr posted:

i wanna do some web dev in the best language (java) should i use play or is there something better

do it in asp.NET MVC4 instead. its way nicer.

Adbot
ADBOT LOVES YOU

Tiny Bug Child
Sep 11, 2004

Avoid Symmetry, Allow Complexity, Introduce Terror

rsjr posted:

i wanna do some web dev in the best language (java) should i use play or is there something better

java is bad. use php instead

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