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
CPColin
Sep 9, 2003

Big ol' smile.

rotor posted:

it seems like there should be a legend of Zelda analogy that would help this guy out

A monad is like Twilight Princess in that all the review sites said it was great and then you used it for a while and didn't have any fun and then never played Skyward Sword.

Adbot
ADBOT LOVES YOU

CPColin
Sep 9, 2003

Big ol' smile.

Progressive JPEG posted:

if i liked twilight princess should i try skyward sword??

im a weirdo that has a gamecube but not a wii

You may have liked it because you didn't have to waggle in order to swing your sword. This is similar to monads because

CPColin
Sep 9, 2003

Big ol' smile.
Yes: http://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html

CPColin
Sep 9, 2003

Big ol' smile.

Max Facetime posted:

or just check for nulls in a less stupid way:

return computer != null && computer.getSoundcard() != null && computer.getSoundcard().getUSB() != null
? computer.getSoundcard().getUSB().getVersion() : "UNKNOWN";

god that article makes me so angry

Eclipse will still flag a bunch of this stuff as "potential" null pointer accesses, because who can say that the second or third call to getSoundcard() won't suddenly return null!?

Also, Eclipse has no idea how to do null analysis on that Optional class. Basically, null analysis should be built into the drat language already.

CPColin
Sep 9, 2003

Big ol' smile.

VikingofRock posted:

Also C++ has its warts but it is a much, much, much, much, much better-designed language than javascript.

One usually is greater than zero, yes.

CPColin
Sep 9, 2003

Big ol' smile.
I had a professor in college who insisted that we create every frame and dialog our program was ever going to display ahead of time. Like, when the program started. So, instead of: *click a button* *slight pause while dialog is built*, it became: *run the program* *long-rear end pause while everything is built*.

I get that, sometimes, JIT is Just Too Late, but man, that was some obnoxious code style.

Meanwhile, the other members of my group made their dialogs appear when the program started, so like twenty windows would immediately pop up.

CPColin
Sep 9, 2003

Big ol' smile.

Shaggar posted:

the two major gui apis for java (swing and eclipse swt) haven't changed since java 1.4.

Hey, they added generics to things like JList.

So now you can pass a Vector<? extends E> to the JList constructor. :downs:

CPColin
Sep 9, 2003

Big ol' smile.

Shinku ABOOKEN posted:

this is why i was playing with kotlin

saying val todolist = ArrayList<Butt>() is much better than ArrayList<Butt> todolist = new ArrayList<Butt>()

And in between the two is List<Butt> todolist = new ArrayList<>().

CPColin
Sep 9, 2003

Big ol' smile.

Notorious b.s.d. posted:

this is really important
type inference doesn't exist to stop you from physically punching in more letters

it's not gonna gently caress up my day's productivity to type out "ArrayList<Butt> todolist = someMethod()" six times. it's going back to fix it later that breaks my balls

if the someMethod() return type changes later, in a world with type inference, i don't have to gently caress with anything as long as the program remains internally consistent. if something will be broken by the change, the compiler will tell me. if not, everything goes along as before.

type inference is having your cake and eating it too. dynamism and also correctness, without trade-offs.

Sounds like you should have used List instead of ArrayList when you declared your local variable!

CPColin
Sep 9, 2003

Big ol' smile.

fleshweasel posted:

no, it's much better to be able to switch to any type in the universe than to be able to switch to another List implementation.

I'd like to see some Java code that called get(int) on a List all over the place, then suddenly started calling get(Integer) on a Map, because the return type of some method changed. Of course, if your code is using an API whose designers found it acceptable to change a return type from List to Map, you've got bigger problems.

CPColin
Sep 9, 2003

Big ol' smile.
Man, what even is the point of functional programming? Every time I see it, I think, "Way to go! You computed a value!"

CPColin
Sep 9, 2003

Big ol' smile.
In Java, I can make lots of things to click on.

CPColin
Sep 9, 2003

Big ol' smile.
And with functional programming, you compute your one value and you're done. There aren't even any buttons to click on. What a silly thing.

CPColin
Sep 9, 2003

Big ol' smile.
The worst part of java.util.Optional is that Eclipse still can't apply @NonNull and @Nullable to it. Java 9 had better bring those annotations into the language specification.

CPColin
Sep 9, 2003

Big ol' smile.
I think it has something to do with cancer

CPColin
Sep 9, 2003

Big ol' smile.

MononcQc posted:

it's a whole language where you can go global_locations => glob_allocations, experts_exchange => expert_sex_change or whatever

Speaking of Experts Exchange, there's a class in our code called "CommentUtilityModel" and I laugh every time I use Eclipse's initial-based autocomplete to type it.

CPColin
Sep 9, 2003

Big ol' smile.
You know what's sick? Declaring an enum in Java that has a function pointer as one of its member variables, then passing an value of that enum to some function and having it go VALUE.getFunction().apply(whatever)

Oh man why did they wait until Java 8 to add these things?

CPColin
Sep 9, 2003

Big ol' smile.

rrrrrrrrrrrt posted:

you could pretty much always do this? nothing stopping an enum from holding a bunch of static objects implementing "functional" interfaces in java pre 8

But now you can write stuff like Something::fart and you don't need the static objects. It takes away an ugliness hurdle, making it more likely that you'll use the pattern effectively.

CPColin
Sep 9, 2003

Big ol' smile.

Mr Dog posted:

Static analyzers can catch uses of null in packages where you've declared null off-limits

Checker Framework is a thing but I haven't bothered to set that up yet.

Yeah, my favorite part about Optional is that Eclipse still can't tell whether it's @NonNull or @Nullable, completely defeating the purpose. Stupid Oracle needs to bring @NonNull and @Nullable into the dang language specification already.

CPColin
Sep 9, 2003

Big ol' smile.

Pie Colony posted:

nested classes are statically bound and not part of the instance of the enclosing object. essentially this will lead to a bunch of fun problems you discover a little too late. this is one example, similar situations arise when Outer actually starts to reference or instantiate Inners

code:
public class Test {
    static class Outer {
        class Inner {
            int get() { return 0; }
        }
    }

    static class OuterP extends Outer {
        class Inner extends Outer.Inner {
            int get() { return 1; }
        }
    }

    public static void main(String[] args) {
        Outer a = new Outer();
        Outer b = new OuterP();

        System.out.println(a.new Inner().get());
        System.out.println(b.new Inner().get());
    }
}
code:
$ javac Test.java
$ java Test
0
0

Well that's what you get for using "Inner" twice.

CPColin
Sep 9, 2003

Big ol' smile.
Every now and then, I notice "Since 1.1" in the Java API documentation and try to imagine what Java 1.0 was like and why anybody wanted to use it.

CPColin
Sep 9, 2003

Big ol' smile.
I got to file a JVM bug with Oracle because this compiles but doesn't run:

code:
// example/a/B.java

package example.a;

class A
{
   public static int print(int value)
   {
      System.out.println(value);
   }
}

public class B extends A
{
}

// example/b/C.java

package example.b;

public class C
{
   public static void main(String[] args)
   {
      java.util.stream.IntStream.range(0, 10).forEach(example.a.B::print);
   }
}
Now I get to wait to see how long until Oracle fixes it! (Or says it's my fault.) Meanwhile, I had to make a bunch of our package-private classes public.

Edit: Added "static" to A.print().

CPColin fucked around with this message at 05:07 on Nov 1, 2015

CPColin
Sep 9, 2003

Big ol' smile.

Brain Candy posted:

no instance of B, so yeah, should be blowing up during the compile

Dang it that A.print() method is supposed to be static. Both the javac compiler and the one Eclipse uses let it through, but it fails at runtime because A isn't public. Even though you can call B.print() just fine normally.

pepito sanchez posted:

you could make B a nested static class in A and it'll work with some refactoring. what were you really trying to do?

We've got generated code as a base level and hand-written code that extends it. The base level is supposed to be package-private, because we don't want everywhere else making references to it instead of going through the public classes. I had some utility code that was trying to use a method reference to call stuff in the package-private base classes and the JVM choked on it with IllegalAccessExceptions.

Eclipse was being smarter than javac, by calling the reference "B.print()" in the compiled classes. The stock compiler was referencing "A.print()," even though that would be illegal at compile time.

CPColin fucked around with this message at 05:10 on Nov 1, 2015

CPColin
Sep 9, 2003

Big ol' smile.
Yeah, that was when I sighed and figured I'd better file it. I even included that line in the report, so they can't claim the method reference shouldn't work.

CPColin
Sep 9, 2003

Big ol' smile.
And what's the deal with lines ending in semicolons!?

CPColin
Sep 9, 2003

Big ol' smile.

piratepilates posted:

ceylon seems kind of neat but seems to go so hard with the type system that I can't get through the docs before wanting to give up on all of it

I want to see what the bytecode the compiler makes looks like. :allears:

CPColin
Sep 9, 2003

Big ol' smile.
Eating poop is dumb because every line starts with a colon.

CPColin
Sep 9, 2003

Big ol' smile.
I might try to learn Ceylon.

Send help.

CPColin
Sep 9, 2003

Big ol' smile.

Notorious b.s.d. posted:

java will get a 'var' type thing sooner or later. (probably not in java 9 tho)

the jep:
http://openjdk.java.net/jeps/286

the 'bug' for the spec is actually better than the jep:
https://bugs.openjdk.java.net/browse/JDK-8151454

Haha why would they introduce both "var" and "val" instead of "var" and "final var"?

CPColin
Sep 9, 2003

Big ol' smile.
So make your IDE automatically add "final" when you have a value that can use it? (Eclipse can already do this.) I'm just saying, why add two keywords when the "final" keyword is already sitting right there?

CPColin
Sep 9, 2003

Big ol' smile.
That "final" keyword is, admittedly, pretty worthless in Java. I see some people insist on putting it on all method parameters. I always want to ask what that's protecting against.

CPColin
Sep 9, 2003

Big ol' smile.

Soricidus posted:

because that's worthless. the value of the distinction is that it captures your intention. adding final automatically just captures the status quo at some arbitrary point in the process of typing in the code, which doesn't tell you anything about whether the variable is supposed to be mutable or not.

So type "final" when you declare the variable? Of course, it's still going to be worthless anyway, because you can still probably mutate the poo poo out of whatever object you just declared.

quote:

and what's wrong with having two reserved type names instead of one? the proposal explicitly doesn't make them full keywords, so your variable called val isn't going to become illegal. and if you have an existing class called val then frankly you deserve everything you get.

I dunno, I just figured the java designers usually have such a boner for reusing keywords, they might reuse one in this case.

CPColin
Sep 9, 2003

Big ol' smile.
I hope everybody understands I'm not defending Java's stupid "final" keyword. I agree that it's pointless most of the time. By extension, "val" would be, too.

Ceylon seems to get it right (for modern values of "right"); immutable is the default and you have to annotate stuff with "variable" to make them behave otherwise.

CPColin
Sep 9, 2003

Big ol' smile.

Soricidus posted:

10 PRINT "Why do A when you can just do B?"
20 PRINT "B is bad because [explanation]. A doesn't have that problem."
30 PRINT "So just do C then?"
40 PRINT "C is bad because [explanation]. A doesn't have that problem."
50 PRINT "So just do B then?"
60 GOTO 20

10 END

CPColin
Sep 9, 2003

Big ol' smile.
That line could use font::canDisplay, too, instead of the arrow syntax. I'm not sure which version is more clear, though.

CPColin
Sep 9, 2003

Big ol' smile.
The code_length field for each method in a Java class takes up four bytes, but:

Java Language Spec posted:

code_length

The value of the code_length item gives the number of bytes in the code array for this method.

The value of code_length must be greater than zero (as the code array must not be empty) and less than 65536.

Thanks a lot, Sun.

CPColin
Sep 9, 2003

Big ol' smile.
Yep. They have room for larger methods, but the spec specifically forbids them. The method that gave me trouble yesterday was the static initializer for an enum, which is even better, because the compiler generates that method, so you can't quickly see how large it's getting. Fortunately, a bunch of the values in the enum were useless and I was able to get rid of them, but still.

CPColin
Sep 9, 2003

Big ol' smile.
Using code generation to generate it! Never cleaning up unused values! Wishing different decisions had been made eight years or so ago!

CPColin
Sep 9, 2003

Big ol' smile.
That's still my favorite dumb justification for allowing underscores in integer literals in Java 8: you can make telephone numbers more readable. Because you're storing telephone numbers in int variables. And typing them in your code. For some reason.

Adbot
ADBOT LOVES YOU

CPColin
Sep 9, 2003

Big ol' smile.
Oh I was wrong. It was Java 7 and the examples were credit card numbers and SSN's:

http://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html

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