|
rjmccall posted:I mean, Java's generics support is already too sophisticated by some metrics — most programmers don't understand the mathematics and just work around (misuses of) the type system with casts. And there's a lot more yet that Java generics can't express, like the co-/contra-variance of List<T> with T. If Java could express covariance and contravariance of type parameters rather than making every method take some List<? extends T> instead, that'd fix my biggest complaint with its type system. Reified types are a nice to have feature, but I think it comes up once every few months for me, and I write a lot of generic code. When it does come up, it's often some variation where the parent class is Bar<BP extends BaseParameter> and class Foo implements Bar<RefinedParameter> or class Foo<RP extends RefinedParameter> implements Bar<RP>. In that case it is possible to recover the type through Foo.class.getGenericInterfaces(). It's even more verbose than usual for Java (and that's saying something) but it's technically possible. You need to find the Type which myType.equals(Bar.class), cast it (unsafely ) to a ParameterizedType and then getActualTypeArguments() to recover the parameter. In this case it would be the Class of RefinedParameter or WildcardType equivalent to ? extends RefinedParameter. In practice, I've found just putting in a method Class<BP> Bar.getParameterType() which Foo implements to return RefinedParameter.class is often sufficient, if inelegant.
|
# ? Nov 29, 2011 04:54 |
|
|
# ? May 15, 2024 08:10 |
|
These last few pages have convinced me that my current plan of avoiding C++ in favour of Haskell or, if I'm desperate and tired, Java is probably not the greatest career move. Is there a handy guide to C++ templates? Are they comparable to Haskell's type system?
|
# ? Nov 29, 2011 14:59 |
|
AlsoD posted:These last few pages have convinced me that my current plan of avoiding C++ in favour of Haskell or, if I'm desperate and tired, Java is probably not the greatest career move. Is there a handy guide to C++ templates? Are they comparable to Haskell's type system? http://www.boostpro.com/mplbook/ It's a bit off at the deep end though, but if you have a general idea of what's going on this book will explain the detail.
|
# ? Nov 29, 2011 16:01 |
|
AlsoD posted:These last few pages have convinced me that my current plan of avoiding C++ in favour of Haskell or, if I'm desperate and tired, Java is probably not the greatest career move. Is there a handy guide to C++ templates? Are they comparable to Haskell's type system? Someone can correct me if I'm wrong, as I'm not a professional programmer, but... It's my understanding that Java, despite it's shortcomings, is a very widespread "pro" language in use by lots of places that pay people to write software. So, if that's what you mean by "not the greatest career move", you may be wrong.
|
# ? Nov 29, 2011 19:23 |
|
Thermopyle posted:Someone can correct me if I'm wrong, as I'm not a professional programmer, but... Hopefully he means "not the greatest move for happiness over the life of my career". You can make money programming in a lot of different languages. If you become proficient at languages you like to use, you will be employable using those same languages.
|
# ? Nov 29, 2011 19:30 |
|
Thermopyle posted:Someone can correct me if I'm wrong, as I'm not a professional programmer, but... It depends on where you want to work. Plenty of jobs would never hire a person for a Java development position unless they had 5 years of Java experience or whatever. But there are plenty of jobs that know an engaged programmer that uses a niche language like Haskell would be able to pick up any language thrown at them, and that what's important is knowing the foundations of programming - not a specific language. Personally, those are the jobs I look for.
|
# ? Nov 29, 2011 19:48 |
|
Kim Jong III posted:what's important is knowing the foundations of programming - not a specific language. They are both important. Having a mastery of all of a specific language's quirks, standard library API knowledge, and general practice with a language will speed development time and reduce accidental introduction of language idiosyncratic errors.
|
# ? Nov 29, 2011 19:59 |
|
AlsoD posted:These last few pages have convinced me that my current plan of avoiding C++ in favour of Haskell or, if I'm desperate and tired, Java is probably not the greatest career move. Is there a handy guide to C++ templates? Are they comparable to Haskell's type system? If by that you mean "not the best move for your employability", Java is if anything more widespread than C++ at this point (although there's a lot of C++ jobs around still, if you find the language appealing). If you mean "not the best move for your happiness", well, I detest both C++ and Java, so I'm not the one to talk to. The General Programming Thread, C/C++ Thread, and Java Thread can probably stuff you full of information on their respective books and job markets as well.
|
# ? Nov 29, 2011 20:14 |
|
Thermopyle posted:Someone can correct me if I'm wrong, as I'm not a professional programmer, but... Nope. Consider you can quite literally hire 20 Java 'developers' from Bangladesh for the price of one in the US. That's the mentality you're up against when you look for Java/PHP/C# jobs. Also all the jobs you see are the equivalent of a pipefitter, just connecting pieces together and you're never doing anything interesting. Alternately, if you're a good Ruby/Python/Clojure/Haskell/Scala/Javascript developer, that automatically excludes you from that whole enterprisey horseshit and far more interesting places take notice of you. NotShadowStar fucked around with this message at 20:54 on Nov 29, 2011 |
# ? Nov 29, 2011 20:52 |
|
NotShadowStar posted:Nope. Consider you can quite literally hire 20 Java 'developers' from Bangladesh for the price of one in the US. That's the mentality you're up against when you look for Java/PHP/C# jobs. This seems hit or miss as more and more companies understand why you put "developers" in quotes.
|
# ? Nov 29, 2011 20:59 |
|
AlsoD posted:These last few pages have convinced me that my current plan of avoiding C++ in favour of Haskell or, if I'm desperate and tired, Java is probably not the greatest career move. Is there a handy guide to C++ templates? Are they comparable to Haskell's type system? I work at a C++-using job, it's a lot of fun. C++ templates are very comparable to Haskell's type system. You can have templates parameterized on types, and you can have templates parameterized on class templates, like in Haskell. For example in Haskell you can do data List a = .... You could talk about the kinds of type constructors: List :: * -> *. List takes a type and produces a type. and in C++ you can do code:
In Haskell you can do data StateT s m a = ... where StateT :: * -> (* -> *) -> * -> *. In C++ you can do code:
The typeclasses of Haskell also have C++ analogues, in the form of overloaded functions. Practical and conscientiously written C++ code does not look at all like Haskell code.
|
# ? Nov 30, 2011 02:03 |
|
If your concern was that Java generics sound too convoluted and weird, then C++ is definitely not going to be a safer haven for you.
|
# ? Nov 30, 2011 02:23 |
|
I've just been picking up a couple of new APIs at work (Thomson Reuters) and it's utterly depressing. C++ code written by poor C developers that skip all the basics, code copy and pasted from many other projects and not even bothering to change introduction text or pre-processor guards. Today I'm looking at C code that is conversely written by poor C++ Windows developers showing no basic understanding of C coding and loving up everything. Who the gently caress puts static prototypes in public headers? Unfortunately this isn't them: http://stackoverflow.com/questions/7912863/is-there-a-way-to-have-static-prototypes-and-public-ones-in-the-same-header-file Apparently the C++ API is cleaned up a bit, they were previously adding "using namespace" inside public headers. The private headers in each example still does it though, and the C APIs certainly don't care about polluting namespace everywhere. What gets me is a "lean high performance" API has examples comprising 20 headers and 20 C++ files for sending demo values and performing absolutely zero processing on the content. Comedy note that a new "ultra performance" API uses select on Windows and this is an API designed and built on Windows and then ported to Solaris and Linux taking really crufty Windows API clones for i18n, configuration files and other services.
|
# ? Nov 30, 2011 04:17 |
|
tef posted:or it's actually a common bug that lots of people overlook. most notably - jon bentley - who went to a lot of effort to check his c code. From way back - this didn't just get past Jon Bentley but also Russ Cox, on the second edition. There is some kind of glass half empty / half full nature to this. You can always improve your work, which is in some ways a cheerful thing to think on. It also means your work - in a medium so tractable that it is only one step removed from thinking - will always be imperfect, and reflect upon our own shortcomings. So we can laugh about relational tables with 1000 columns and rolling your own passwords and using comments as source control and the for-switch idiom, but I think we should spend some time focusing on subtle problems that we have difficulty with, instead of simple problems that we trivially avoid. I've spent quite awhile trying to come up with one that was understandable, but they are all so domain specific or long-winded that I cannot. I apologize.
|
# ? Nov 30, 2011 04:42 |
|
Thanks for wrecking the thread you jerk.
|
# ? Nov 30, 2011 06:28 |
|
Sooo, here's a horror I wrote...code:
|
# ? Nov 30, 2011 16:20 |
|
If we're on to horrors we write ourselves, here's something I did:code:
|
# ? Nov 30, 2011 21:04 |
|
Jabor posted:Runnable stuff I don't get it, why does your code need a Runnable wrapper and what is "wat"?
|
# ? Nov 30, 2011 21:14 |
|
He's assigning to a final variable. I guess final as applied to array variables in Java doesn't make the elements of the array itself final? Or did this even compile?
|
# ? Nov 30, 2011 21:23 |
|
TasteMyHouse posted:He's assigning to a final variable. I guess final as applied to array variables in Java doesn't make the elements of the array itself final? Or did this even compile? A final variable in Java is a special trick that allows closure-like behavior. See this page for more information.
|
# ? Nov 30, 2011 21:25 |
|
Suspicious Dish posted:A final variable in Java is a special trick that allows closure-like behavior. Oh, that's cool. Out of curiosity, is there a way to declare an immutable array in java?
|
# ? Nov 30, 2011 21:26 |
|
Suspicious Dish posted:A final variable in Java is a special trick that allows closure-like behavior. ClosuresThatWorkAroundFinalLimitation posted:Inner classes in Java capture ("close over") the lexical scope in which they are defined. But they only capture variables that are declared "final". Never programming in Java again was the best decision I ever made. Bozart posted:There is some kind of glass half empty / half full nature to this. You can always improve your work, which is in some ways a cheerful thing to think on. It also means your work - in a medium so tractable that it is only one step removed from thinking - will always be imperfect, and reflect upon our own shortcomings. So we can laugh about relational tables with 1000 columns and rolling your own passwords and using comments as source control and the for-switch idiom, but I think we should spend some time focusing on subtle problems that we have difficulty with, instead of simple problems that we trivially avoid. While I agree with this, I think it may be better off as a separate thread - what makes the horrors here horrors is that many of them are trivially avoidable even by novice programmers. "Coding subtle problems that bedevil even experienced programmers" doesn't have quite the same ring to it. Furthermore, as you point out, it's a lot harder to come up with examples. That said, I'd read the poo poo out of such a thread.
|
# ? Nov 30, 2011 21:37 |
|
I think the latest attempt at adding lambdas in Java 7 after the last abortion is really just a syntax macro for anonymous inner classes, so you can only access final variables outside the scope of it. Which defeats all of the point of a real lambda or closure anyway but welp java.quote:and Java has been worked on by some of the greatest minds in the field Every single one of them should be called out and publicly shamed. They took the brilliant Smalltalk language and hosed it all up because they thought that they couldn't sell something to aspergers filled engineers if it didn't look tangentially like C++.
|
# ? Dec 1, 2011 01:24 |
|
ToxicFrog posted:
Closures over non-final variables can lead to some interesting situations: code:
|
# ? Dec 1, 2011 01:35 |
|
1337JiveTurkey posted:Closures over non-final variables can lead to some interesting situations: I don't see how this is a "closures over non-final variables" issue as opposed to a "modifying shared state from multiple threads without synchronization" issue.
|
# ? Dec 1, 2011 01:46 |
|
NotShadowStar posted:Every single one of them should be called out and publicly shamed. They took the brilliant Smalltalk language and hosed it all up because they thought that they couldn't sell something to aspergers filled engineers if it didn't look tangentially like C++. I should take the time to point out that there are three things that we call Java:
Suspicious Dish fucked around with this message at 02:13 on Dec 1, 2011 |
# ? Dec 1, 2011 02:07 |
|
Suspicious Dish posted:I should take the time to point out that there are three things that we call Java: At least in my case, when I bitch about Java, I am specifically bitching about Java the language or Java the library. The JVM is pretty sweet and I'm a big fan of Scala. This is not to say that it couldn't be improved (tail call elimination and no type erasure, for example), but as far as I can tell all of my complaints about the JVM boil down to it needing to maintain backwards compatibility with every brain-damaged design decision Java-the-language has been subject to over the years. Also, AWT is just as unpleasant and terrible no matter what OS you're on.
|
# ? Dec 1, 2011 02:52 |
|
The JVM wasn't a Sun thing though, that came from the complicated history of Smalltalk. Indeed the smart people concluded correctly that the C++ style syntax wasn't the way to go but braindumbs at Sun was having none of it.
|
# ? Dec 1, 2011 03:14 |
|
NotShadowStar posted:Every single one of them should be called out and publicly shamed. They took the brilliant Smalltalk language and hosed it all up because they thought that they couldn't sell something to aspergers filled engineers if it didn't look tangentially like C++. Well... Yeah, they were right. Sun probably couldn't have foisted java as effectively as it did if it was much different than it is.
|
# ? Dec 1, 2011 05:21 |
|
This loving stack overflow thread: http://stackoverflow.com/questions/8339192
|
# ? Dec 1, 2011 10:55 |
|
ToxicFrog posted:I don't see how this is a "closures over non-final variables" issue as opposed to a "modifying shared state from multiple threads without synchronization" issue. There's nothing to synchronize on because there's no reason you ever need to synchronize a local variable when only its thread can touch it. It's also a "the stack frame doesn't exist any more" issue and a "allowing pointers to reference the stack" issue. They're not insurmountable issues, but they add complexity to the language and reduce the scope of optimizations. Additionally, closures being by value means they behave consistently with method call semantics: No variable will be changed in a method unless it happens within the method itself. Java in this case chose consistency over "more checkboxes = better than" language design.
|
# ? Dec 1, 2011 12:11 |
|
quote:There's nothing to synchronize on because there's no reason you ever need to synchronize a local variable when only its thread can touch it. What? You're spawning 100 instances of that same thread. Yes it is a concurrency issue.
|
# ? Dec 1, 2011 13:14 |
|
Beef posted:What? You're spawning 100 instances of that same thread. Yes it is a concurrency issue. Only because it's mutable. It's a violation of underlying language invariants for the sake of not using a Callable instead of a Runnable. That's what gets us languages like PHP.
|
# ? Dec 1, 2011 13:29 |
|
turby posted:This loving stack overflow thread: Q : "How do I make a hashing function that uses at most 20 characters in a string?" A : "Use substring!" A : "Use LINQ!" A : "Nested ternary operators!"
|
# ? Dec 1, 2011 14:40 |
|
this is my own code but it's awful as gently caress so I'm posting it I have a Java library for Terraria player files. Items in the game previously were identified solely by their names. I went the immutable route and set up a static factory as so: (some irrelevant lines removed) code:
code:
|
# ? Dec 1, 2011 21:13 |
|
Aleksei Vasiliev posted:
I hope you learned your lesson.
|
# ? Dec 1, 2011 21:37 |
|
1337JiveTurkey posted:Only because it's mutable. It's a violation of underlying language invariants for the sake of not using a Callable instead of a Runnable. That's what gets us languages like PHP. What underlying language invariants does this violate? You started 100 threads that all call a method on an object that mutates shared state without synchronization. If you didn't want to have that shared state then don't close over it. Or assign it to a closure-local variable. C# handles this just fine.
|
# ? Dec 2, 2011 01:26 |
|
code:
|
# ? Dec 2, 2011 01:42 |
|
Uh can't you write if (thefile_counter == 54) { thefile_counter = 0; } on the assignment and give him an F because ffffffffff
NotShadowStar fucked around with this message at 03:51 on Dec 2, 2011 |
# ? Dec 2, 2011 02:23 |
|
|
# ? May 15, 2024 08:10 |
|
DotFortune posted:
Switch statements are jump tables, so they're faster than if statements!
|
# ? Dec 2, 2011 02:42 |