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
NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

hobbesmaster posted:

Has he never heard of Scala or something? He mentions functional programming in the post so he obviously knows the phrase, but doesn't recognize what hes trying to do?

Forget Scala, is he aware of Java 8's functional interfaces? I have never written a line of Java and I still know they're tailor-made for his design

Adbot
ADBOT LOVES YOU

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

VikingofRock posted:

Does Java have auto yet? That made C++11 much less verbose IMO.

No, but C# has had it for ages.

Soricidus
Oct 21, 2010
freedom-hating statist shill
Java has it in library form (lombok.val).

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Soricidus posted:

Java has it in library form (lombok.val).

Does this val get resolved at compile-time, or does it use reflection / late-binding / other runtime tools? The documentation seems minimal.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)

I'd be far more impressed if everything was an iterator :colbert:.

http://pastebin.com/raw/TRCkiUvD (but it's really slow...)

It's really funny whenever someone comes up with a fancy name for things like a tree of constructors.

e: I didn't know that Java doesn't have list comprehension ... do you really have to make an interface for everything? ... Wait, he has one public method, but it's not a constructor? It looks like he's just making a weird expression tree?

dougdrums fucked around with this message at 17:22 on Aug 17, 2016

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Lombok isn't Java.

Bongo Bill
Jan 17, 2012


This is just verbose currying.

Volte
Oct 4, 2004

woosh woosh
Typical Java programmer dogma, a set of rules to follow rigidly and an implication that following them no matter what is more important than using your brain.

quote:

This technique does create an explosion of classes and you have to come up with names for all of them. It’s not always easy but whenever I struggle with this I feel like there is a concept that needs to be named, I just can’t think of the name for it. It’s rarely a situation where I feel like the concept doesn’t exist.
I have never seen a clearer case of Stockhome Syndrome.

Volte
Oct 4, 2004

woosh woosh
Plato's cave allegory applies pretty much directly to the Java world when you think about it

JawnV6
Jul 4, 2004

So hot ...

LOOK I AM A TURTLE posted:

Haskell gets this right. If you want to compare objects using the == operator you have to derive the Eq typeclass, and for types with members that themselves don't implement Eq (e.g. functions) it's usually impossible to define Eq in a consistent way
Why would function equality be impossible to define? Aren't they first class?

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.
How would you define it? What metric would you use, outside of testing every possible value?

code:
shouldWork1       =    (+ 3)

shouldWork2     x = ((x + 4) - 1)
code:
shouldn'tWork1    =   (+ 3)

shouldn'tWork2 69 = 420
shouldn'tWork2 x  = (x + 3)

Sinestro fucked around with this message at 18:21 on Aug 17, 2016

Bongo Bill
Jan 17, 2012

Some pairs of functions can be proven equivalent, but there's no general way.

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.

Bongo Bill posted:

Some pairs of functions can be proven equivalent, but there's no general way.

In a language without side effects, you could do it by testing every single value of the input types, if it's even a type with a limited number of residents, but that'd quickly get impractical.

JawnV6
Jul 4, 2004

So hot ...

Sinestro posted:

How would you define it? What metric would you use, outside of testing every possible value?
I've been told type systems obviate the need for such crude methods of actually testing things. You're telling me "stable sort" is beyond imagination as a descriptor?

Bongo Bill
Jan 17, 2012

Type systems can only enforce what they can prove.

VikingofRock
Aug 24, 2008




JawnV6 posted:

Why would function equality be impossible to define? Aren't they first class?

You can define function equality, but it's impractical to do so in general. Here's some code that will work for any functions with enumerable, bounded inputs and equality-testable outputs, and I've provided an examples using functions of type (Bool -> Int) and (Int16 -> Int16):

code:
import Data.Int

-- define Eq for appropriate functions

instance (Enum a, Bounded a, Eq b) => Eq (a -> b) where
    f == g = all (\x -> f x == g x) [minBound..maxBound]


-- examples for (Bool -> Int)

f1 :: Bool -> Int
f1 True = 1
f1 False = 0

f2 :: Bool -> Int
f2 bool = if bool then 1 else 0

f3 :: Bool -> Int
f3 bool = if bool then 0 else 1

-- examples for (Int16 -> Int16)

shouldWork1 :: Int16 -> Int16
shouldWork1       =    (+ 3)

shouldWork2 :: Int16 -> Int16
shouldWork2     x = (x + 4) - 1

shouldn'tWork1 :: Int16 -> Int16
shouldn'tWork1    =   (+ 3)

shouldn'tWork2 :: Int16 -> Int16
shouldn'tWork2 69 = 420
shouldn'tWork2 x  = x + 3

-- run examples

main = do
    print $ f1 == f2 -- prints True
    print $ f1 == f3 -- prints False
    print $ shouldWork1 == shouldWork2 -- prints True
    print $ shouldn'tWork1 == shouldn'tWork2 -- prints False

VikingofRock fucked around with this message at 19:42 on Aug 17, 2016

theratking
Jan 18, 2012

Hammerite posted:

That's bonkers, but how did this issue get noticed in the first place? Do your testers go around typing stuff into the address bar without actually going to the page, just in case it has an effect? That's some comprehensive testing. I don't understand how it got picked up in the first place, unless there are other circumstances in which Chrome does this prefetching.

What does Chrome do in failure cases? For example what does it do if the prefetched JavaScript goes into a loop?
This feature is called "prerender" and it is pretty seriously broken on a fundamental level. Afaik there is a project to replace it with a prefetch that just scans the main html to stuff the http cache.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Volte posted:

Java's no inherently worse than any other language, but it does seem to be the lingua franca of "coders" who see programming less as a creative expression of sound engineering principles, and more as glorified paperwork---the software counterpart to pencil-pushing-bureaucrat-types whose definition of "good idea" is "follows the established procedure". It's hard to find beauty in a joyless world. Scala must be what Java programmers see when they dream at night...

Oh yes. This, exactly.

Absurd Alhazred
Mar 27, 2010

by Athanatos

quote:

“Extreme SRP” has all the advantages of SRP:

  • Code complexity is reduced by being more explicit and straightforward
  • Loose coupling
  • Improved readability

The methods are very small and easy to understand. But, if you’re looking for a specific leaf and you don’t know its name, you have to traverse the tree to get there. Whereas a lot of these classes may be inlined into one method when using traditional techniques so the code would be easier to find. This is one of the downsides you have to live with when you practice “Extreme SRP”.

LOL, yeah, when I think readability, I think having to read 20000 different files to get at what the hell a piece of code trying to do. I'd love to see some of those debugging stack traces, too. :allears:

hobbesmaster
Jan 28, 2008

I just want to see what he names currying and how he'll gently caress it up. :allears:

comedyblissoption
Mar 15, 2006

the single responsibility principle is an opportunity for extreme bikeshedding

Bongo Bill
Jan 17, 2012

We can't just not paint the bike shed.

Athas
Aug 6, 2007

fuck that joker

Sinestro posted:

How would you define it? What metric would you use, outside of testing every possible value?

code:
shouldWork1       =    (+ 3)

shouldWork2     x = ((x + 4) - 1)
code:
shouldn'tWork1    =   (+ 3)

shouldn'tWork2 69 = 420
shouldn'tWork2 x  = (x + 3)

What about structural equality? Equality doesn't have to mean equivalence. It's not inconceivable to define a language where the bodies of functions (along with their lexical environment) must be kept around in order to permit structural equality. Hardly useful, though.

And of course, plenty of languages just define function equality as equality of identity and compile it to a pointer comparison.

Soricidus
Oct 21, 2010
freedom-hating statist shill

NihilCredo posted:

Does this val get resolved at compile-time, or does it use reflection / late-binding / other runtime tools? The documentation seems minimal.

Lombok is all compile-time.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Bongo Bill posted:

We can't just not paint the bike shed.

What if we seal it?

FamDav
Mar 29, 2008

Athas posted:

What about structural equality? Equality doesn't have to mean equivalence. It's not inconceivable to define a language where the bodies of functions (along with their lexical environment) must be kept around in order to permit structural equality. Hardly useful, though.

And of course, plenty of languages just define function equality as equality of identity and compile it to a pointer comparison.

Then what's the point? Only being able to know if two functions are literally the same exact function by reference is dumb, and forces the compiler to not inline functions or have multiple copies in your program.

canis minor
May 4, 2011

Today CSS guy removed name attribute from a form because he didn't know what that attribute does. I... I just don't know how to respond to that.

I guess, sure - if you've got options such as asking, or googling, or using common sense of not touching something you don't understand, you can always remove stuff...

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

FamDav posted:

Then what's the point? Only being able to know if two functions are literally the same exact function by reference is dumb, and forces the compiler to not inline functions or have multiple copies in your program.

In what scenario would you (1) have multiple identical or equivalent functions in your code, and (2) be unable to delete the unnecessary copies?

eth0.n
Jun 1, 2012

FamDav posted:

Then what's the point? Only being able to know if two functions are literally the same exact function by reference is dumb, and forces the compiler to not inline functions or have multiple copies in your program.

Avoiding having multiple copies of a function is generally good either way: it improves instruction cache performance. Even if you end up with multiple copies (I believe it can happen with DLLs), it's still possible to ensure that when the address is taken, it's to one canonical copy.

And inlining has nothing to do with a language's function comparison semantics. Inlining is a primary feature of C++, and it only supports testing function equality by address comparison.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Yes, but making an absolute guarantee of never having multiple copies of a function hurts performance, too. It's work that has to be done at load time for every single inline function, which hugely bloats symbol tables and makes program launch take forever.

As far as I know, MSVC does not make any effort to ensure that the address of an inline function compares equal across DLL boundaries. I don't think PE supports that at all. ELF and Mach-O do, and the default behavior in GCC and Clang tries to preserve address-equality — but it's terrible for performance, which is why there are options like -fvisibility-inlines-hidden and -fvisibility=hidden.

Also, inlining is not a primary feature of C++. "inline" doesn't say anything about whether a function will actually be inlined; it just changes the linkage rules of the declaration.

FamDav
Mar 29, 2008

NihilCredo posted:

In what scenario would you (1) have multiple identical or equivalent functions in your code, and (2) be unable to delete the unnecessary copies?

have you never written a single lambda in haskell? it is entirely possible to have multiple instances of the same function declared across multiple modules.

eth0.n posted:

Avoiding having multiple copies of a function is generally good either way: it improves instruction cache performance. Even if you end up with multiple copies (I believe it can happen with DLLs), it's still possible to ensure that when the address is taken, it's to one canonical copy.

And inlining has nothing to do with a language's function comparison semantics. Inlining is a primary feature of C++, and it only supports testing function equality by address comparison.

By inlining, I meant an inline declaration of an anonymous function in haskell and whether there will be a single canonical version of it across your entire program. Poor choice of words.

a more general haskell-specific response is that allowing pointer equality would break referential transparency.

EDIT:

Also, suppose you have two functions which have separate declarations and bodies. The compiler decides after optimization that they are in fact logically equivalent and produces a single declaration that is used at either's call site. Do these compare equal, do they not? What about when a new compiler version decides it is faster for them to be declared independently?

FamDav fucked around with this message at 17:06 on Aug 18, 2016

eth0.n
Jun 1, 2012

FamDav posted:

By inlining, I meant an inline declaration of an anonymous function in haskell and whether there will be a single canonical version of it across your entire program. Poor choice of words.

C++ has those too, lambdas. Although only non-capturing lambdas can be equality compared (by decaying them into function pointers).

rjmccall posted:

As far as I know, MSVC does not make any effort to ensure that the address of an inline function compares equal across DLL boundaries.

It does if you dllexport/dllimport it properly, like any other function.

rjmccall posted:

Also, inlining is not a primary feature of C++. "inline" doesn't say anything about whether a function will actually be inlined; it just changes the linkage rules of the declaration.

Yes, I know what the "inline" keyword means. What I meant was inlining is central to the design and usage conventions of C++, so clearly a language with reference-equality functions can have inline functions (which, turns out, isn't what the OP meant to say, anyway). The main benefit of C++ is it allows highly abstracted concepts to translate into well-optimized assembly. If inlining weren't supported, the cost of abstraction would go way up, and performant C++ would have to look a lot different (and less readable/maintainable) than now.

eth0.n fucked around with this message at 17:41 on Aug 18, 2016

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

eth0.n posted:

It does if you dllexport/dllimport it properly, like any other function.

Ah, I see how they do it. Okay, yes, if you can identify a unique DLL that owns the inline function and you're willing to do an arcane dance with macros to make it happen, you can get pointers to inline functions to match across DLLs. My point stands that this is still basically a useless promise that does nothing but cost performance if you actually honor it. For example, I believe MSVC de-duplicates template instantiations, despite that being clearly illegal under the spec.

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today

toiletbrush posted:

I don't know who the horror is here, but...
Isn't this sort of thing why you're never supposed to perform side effects as a result of a GET request?

necrotic
Aug 2, 2005
I owe my brother big time for this!

Ralith posted:

Isn't this sort of thing why you're never supposed to perform side effects as a result of a GET request?

Yes

rarbatrol
Apr 17, 2011

Hurt//maim//kill.

canis minor posted:

Today CSS guy removed name attribute from a form because he didn't know what that attribute does. I... I just don't know how to respond to that.

I guess, sure - if you've got options such as asking, or googling, or using common sense of not touching something you don't understand, you can always remove stuff...

Recently a guy at work accidentally (nobody has any idea how) deleted 1/2 of our code base in one commit with a message like "lol idk why this is happening this is weird" and then rolled it back with the next commit.

Maybe... don't commit that poo poo in the first place?

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

Volte posted:

Typical Java programmer dogma, a set of rules to follow rigidly and an implication that following them no matter what is more important than using your brain.
I have never seen a clearer case of Stockhome Syndrome.

StockholmSyndromeFactoryFactory

Zopotantor
Feb 24, 2013

...und ist er drin dann lassen wir ihn niemals wieder raus...

rarbatrol posted:

Recently a guy at work accidentally (nobody has any idea how) deleted 1/2 of our code base in one commit with a message like "lol idk why this is happening this is weird" and then rolled it back with the next commit.

Maybe... don't commit that poo poo in the first place?

hosed up his worktree and didn't know how to fix it?

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?
When you are too much in love with Java 8 (seen at work):

code:
    private static boolean mapActive(LocationExt bookplanSurgeryRoom) {
        String bookplanStatus = bookplanSurgeryRoom.getStatus();

        ImmutableMap<String, Boolean> statusMap = ImmutableMap.of(
                FHIRStatus.ACTIVE, true, 
                FHIRStatus.INACTIVE, false);
        
        Boolean mappedActive = Optional.ofNullable(statusMap.get(bookplanStatus))
                .orElseGet(() -> {
                    LOGGER.warn("xxx {} yyy {} zzz", bookplanStatus, bookplanSurgeryRoom);
                    return true;
                });
        return mappedActive;
    }
What about just:

code:
    private static boolean mapActive(LocationExt bookplanSurgeryRoom) {
        String bookplanStatus = bookplanSurgeryRoom.getStatus();
        switch (bookplanStatus) {
            case FHIRStatus.ACTIVE:
                return true;
            case FHIRStatus.INACTIVE:
                return false;
            default:
                LOGGER.warn("xxx {} yyy {} zzz", bookplanStatus, bookplanSurgeryRoom);
                return true;
        }
    }

Adbot
ADBOT LOVES YOU

canis minor
May 4, 2011

http://help.adobe.com/en_US/livecycle/11.0/DesignerScriptingRef/search.html?gsa=1&q=app

Oh Adobe :allears:

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