|
McGlockenshire posted:So if we continue this discussion on the next page, does that mean we have to go back and refactor our posts?
|
# ? Dec 4, 2012 14:50 |
|
|
# ? May 30, 2024 13:55 |
|
Dajax. I thought about writing something like this as an April Fools' gag, but it seems people who actually thought it was a good idea beat me to it.
|
# ? Dec 4, 2012 16:30 |
|
code:
and yes is really is PhonenUmber
|
# ? Dec 4, 2012 17:12 |
|
Suspicious Dish posted:Dajax. Do you mean that example or the project itself?
|
# ? Dec 4, 2012 18:42 |
|
dwazegek posted:
What if you want an obscure Blemmye king's color of brown?
|
# ? Dec 4, 2012 18:49 |
|
Every time I look at my buddy's methods he ALWAYS returns the object Boolean instead of a regular boolean. When I ask him why he uses the object instead of the primitive he stares blankly at me.
|
# ? Dec 4, 2012 20:51 |
|
Mesothelioma posted:Every time I look at my buddy's methods he ALWAYS returns the object Boolean instead of a regular boolean. When I ask him why he uses the object instead of the primitive he stares blankly at me. To be fair, and as a Java fanboy myself, this is pretty bizarre behavior on the language's side. All types are object classes and all type names should start with a capital letter. Except primitives aren't classes and their types do not start with a capital letter. Except there are also classes named after the primitives whose names do start with a capital letter, and the compiler will automatically convert between the differently cased types. Except generics must use the capital version, and null is not a permitted value for the lowercase version. e: wow, I skipped a lot of words the first time writing that Amarkov fucked around with this message at 21:27 on Dec 4, 2012 |
# ? Dec 4, 2012 21:13 |
|
I still remember the first time I had to chase down a null pointer exception due to the auto-unboxing of a Boolean value. Took quite a while because it "obviously" wasn't the problem.
|
# ? Dec 4, 2012 21:20 |
|
Jonnty posted:Do you mean that example or the project itself? I think that example is pretty exemplary of the project as a whole.
|
# ? Dec 4, 2012 21:48 |
|
Suspicious Dish posted:Dajax. Am I missing something or is this just basically just using JavaScript to execute Python code that could have just been written in JavaScript?
|
# ? Dec 4, 2012 22:18 |
|
edit: nm, it's astonishingly fast but is apparently AJAX
|
# ? Dec 4, 2012 22:20 |
Optimus Prime Ribs posted:Am I missing something or is this just basically just using JavaScript to execute Python code that could have just been written in JavaScript? Uh, I'm pretty sure what you are looking at there are some stupid examples. The Python code runs server-side and can obviously do whatever the server is able to, such as pulling stuff from a database. The interface it gives seems to be a clean RPC style where you aren't actively interacting with XHR objects or JSON or whatever, but simply pass objects into functions that happen to run at a remote. I don't see any WTF there, rather it looks useful and well-thought out. Also, I'm quite sure one of the basic examples made for almost any RPC system is the "add two numbers" function. Surely it's useless for any practical purpose, but it's simple and shows that calls and marshalling works.
|
|
# ? Dec 4, 2012 22:26 |
|
Amarkov posted:Except there are also classes named after the primitives whose names do start with a capital letter, and the compiler will automatically convert between the differently cased types. Except when doing so would make your code cleaner, more concise, or easier to debug, in which case the compiler will just take a steaming poo poo in your mouth and tell you to convert by hand. There are a lot of things I dislike about Java but its schizophrenia regarding objects vs primitives probably heads the list.
|
# ? Dec 4, 2012 22:42 |
|
It's this line of Python that's the horror:Python code:
Python code:
|
# ? Dec 4, 2012 22:56 |
|
nielsm posted:Uh, I'm pretty sure what you are looking at there are some stupid examples. The Python code runs server-side and can obviously do whatever the server is able to, such as pulling stuff from a database. The interface it gives seems to be a clean RPC style where you aren't actively interacting with XHR objects or JSON or whatever, but simply pass objects into functions that happen to run at a remote. Okay, that makes sense. The examples they give just look like over complicating problems that could have been solved with straight-up JavaScript, but being able to do AJAX-type stuff without having to muck around with XHR objects is a plus in my book. I don't know how well that would work with frameworks like jQuery or MooTools that use their own AJAX poo poo, but supposedly it does. Suspicious Dish posted:
Well that certainly is something.
|
# ? Dec 4, 2012 23:06 |
|
ToxicFrog posted:Except when doing so would make your code cleaner, more concise, or easier to debug, in which case the compiler will just take a steaming poo poo in your mouth and tell you to convert by hand. Oh poo poo, C# has for-loop iterators that uses almost identical syntax to JavaScript... Let's deliberately pick a different syntax. Oh poo poo, C# added Generics... Let's add them too. Oh all these generic parameters? gently caress 'em, it's all Object at runtime baby! Oh poo poo, C# added lambda expressions, closures, and functions as first-class objects... Well, who wants to actually persist variables modified in the outer scope, that poo poo's for sperglords. We'll have our own lambdas, and blackjack, and hookers... In fact forget the lambdas. And the blackjack. Eh gently caress it, forget the whole thing. Repeat ad-infinitum. P.S. what's a Delegate?
|
# ? Dec 4, 2012 23:06 |
|
Amarkov posted:To be fair, and as a Java fanboy myself, this is pretty bizarre behavior on the language's side. All types are object classes and all type names should start with a capital letter. Except primitives aren't classes and their types do not start with a capital letter. Except there are also classes named after the primitives whose names do start with a capital letter, and the compiler will automatically convert between the differently cased types. Except generics must use the capital version, and null is not a permitted value for the lowercase version. Agreed on the part where they shouldn't have exposed the primitives in the first place. Autoboxing, which is what you're talking about with the automatic boolean <-> Boolean, int <-> Integer, and other conversions, is necessary because primitives are values whereas classes are references (explaining for the benefit of others since you know what I'm talking about). The part where this sucks is when the object is null, the primitive conversion fails. Thing is, collections should return null, i.e. if you're using a map and the key doesn't have a corresponding value, you've got to return null. So of course collections must be able to return null - thus, they must only take objects. That by itself can be inconvenient and might need some care, but isn't terribly horrific. What's horrific is that at some point the automatic optimization will cease to operate. Java code:
|
# ? Dec 4, 2012 23:22 |
|
Suspicious Dish posted:It's this line of Python that's the horror:
|
# ? Dec 4, 2012 23:37 |
|
Ender.uNF posted:Oh poo poo, C# added Generics... Let's add them too. Oh all these generic parameters? gently caress 'em, it's all Object at runtime baby! C# added generics about a year after Java did, and their decision to use reified generics instead of type erasure forced a huge compatibility break that was actually a serious problem for C# programmers at the time (and still noticeably bloats C# deployments). The Java developers decided they really didn't have that option give that they had a large base of deployed software that they cared about. Ender.uNF posted:Oh poo poo, C# added lambda expressions, closures, and functions as first-class objects... Java added closures via anonymous inner classes in 1997, in Java 1.1. When they did so, they decided on a particular, somewhat conservative model for capturing variables. Since then, they've decided that all of their closure-like extensions should behave essentially the same way, i.e. no mutable captures. You can fault them for these decisions, but saying the language features were added in response to C# is pretty dumb.
|
# ? Dec 4, 2012 23:44 |
|
Mesothelioma posted:Every time I look at my buddy's methods he ALWAYS returns the object Boolean instead of a regular boolean. When I ask him why he uses the object instead of the primitive he stares blankly at me.
|
# ? Dec 5, 2012 00:51 |
|
Doctor w-rw-rw- posted:So the range of input can unexpectedly blow up your program, because now your memory's all hosed. Edit: exact thresholds are +127 and -128. Yay bytes. Freakus fucked around with this message at 02:33 on Dec 5, 2012 |
# ? Dec 5, 2012 02:10 |
|
rjmccall posted:C# added generics about a year after Java did, and their decision to use reified generics instead of type erasure forced a huge compatibility break that was actually a serious problem for C# programmers at the time (and still noticeably bloats C# deployments). The Java developers decided they really didn't have that option give that they had a large base of deployed software that they cared about. You know I think youre a genius dude, I wasn't serious, more lamenting the design-by-committee approach and eternally slow pace, something C++ has also long suffered from. Actually that applies to a lot of things. There's a huge benefit to having a single group make decisions (see Objective-C and LLVM from Apple and C# from MS), but it has drawbacks too. I look at Java programmers the way people in this thread look at PHP programmers. Once you've used something much better, it's hard to go back. Java was a good step forward but it hasn't kept up with the times. I'm also starting to understand why the LISP people are so insufferable... Once you start using functions as first-class objects it just opens up whole new ways to write better code with less boilerplate, anything else seems primitive by comparison. I'm not sure what you're referencing with the c# transition. The run times installed side by side and you can use old assemblies in the newer one so it was relatively painless. Now that we're on the other side it's a non-issue. On bloat, it only instantiates the generic template once for all reference types so I'm not sure what you are referencing. On value types it instantiates once per type to avoid the automatic box/unbox people were discussing earlier. Edit: just to be clear, I do not think Java stole, borrowed, or did anything in response to C#, and neither language is truly new as they're in the C family and borrow from a lot of earlier work.
|
# ? Dec 5, 2012 02:20 |
|
Doctor w-rw-rw- posted:So the range of input can unexpectedly blow up your program, because now your memory's all hosed. A byte takes 1 byte, a Byte takes 16 bytes.
|
# ? Dec 5, 2012 02:34 |
|
Aleksei Vasiliev posted:Wait, you're saying that Java shouldn't have exposed primitives and complaining about memory usage of the object versions? What are those other 12 bytes for?
|
# ? Dec 5, 2012 02:37 |
|
Suspicious Dish posted:What are those other 12 bytes for? (obviously this is implementation-dependent but this is accurate for HotSpot afaik)
|
# ? Dec 5, 2012 02:43 |
|
Suspicious Dish posted:What are those other 12 bytes for? 8 bytes for the object header, and 4 bytes for the member. The member data is allocated in 8 byte chunks, so you'll waste an additional 4 bytes that won't be used. quote:The class takes up at least 8 bytes. So, if you say new Object(); you will allocate 8 bytes on the heap.
|
# ? Dec 5, 2012 02:44 |
|
Geekner posted:and 4 bytes for the member (good luck finding a citation for this though)
|
# ? Dec 5, 2012 02:48 |
|
I'm not trying to rag on you; I just take these things pretty seriously because I have to appreciate the decisions and trade-offs involved. I definitely am not a huge fan of the Java language design process or its results.Ender.uNF posted:I look at Java programmers the way people in this thread look at PHP programmers. Once you've used something much better, it's hard to go back. Java was a good step forward but it hasn't kept up with the times. I'm also starting to understand why the LISP people are so insufferable... Once you start using functions as first-class objects it just opens up whole new ways to write better code with less boilerplate, anything else seems primitive by comparison. Yeah, I can understand some of the language/environment issues stopping Java from delivering really good first-class functions, but yeesh. Ender.uNF posted:I'm not sure what you're referencing with the c# transition. The run times installed side by side and you can use old assemblies in the newer one so it was relatively painless. Now that we're on the other side it's a non-issue. Well, I asume that they haven't stopped shipping the old system libraries. That's permanent disk footprint, and it's a pretty serious memory footprint if any applications need them. I'm aware that disk footprint isn't a traditional area of concern for Microsoft. Ender.uNF posted:On bloat, it only instantiates the generic template once for all reference types so I'm not sure what you are referencing. On value types it instantiates once per type to avoid the automatic box/unbox people were discussing earlier. Well, technically there has to be metadata instantiated for different reference types so that type identity works, but you're right that code doesn't usually have to be duplicated. Ender.uNF posted:Edit: just to be clear, I do not think Java stole, borrowed, or did anything in response to C#, and neither language is truly new as they're in the C family and borrow from a lot of earlier work. And to be clear on my part, I don't think there's anything wrong with C# borrowing ideas from Java†. Java got somethings right and made some mistakes, and Microsoft got to learn from both and, in so doing, make a strictly better language (at least along those dimensions). † Which they obviously did. It's interesting to speculate about a world in which Microsoft had been able to exercise some creative control on Java and the JVM, instead of getting slapped by Sun for their trouble and then stomping off to implement their own thing. It's probably a world with massive fragmentation within the Java market and a lot less interesting language innovation from Microsoft, so it's all for the best.
|
# ? Dec 5, 2012 03:00 |
|
Aleksei Vasiliev posted:It's 8 bytes for the object header, 1 byte for the byte, 7 bytes for padding to align the object to a multiple of 8. The auto-boxing makes it possible for the optimizer to inline these so that a "Byte" is just in a register, no? I also assume that the "byte" primitive isn't on the heap, so it actually takes 4 or 8 bytes depending on the architecture of the system
|
# ? Dec 5, 2012 03:07 |
|
Aleksei Vasiliev posted:Wait, you're saying that Java shouldn't have exposed primitives and complaining about memory usage of the object versions? Don't forget the cost of storing a pointer. For Byte and Boolean, which have complete caches, that's the only memory use that really matters — unless you're an idiot and calling new Byte(b) manually, boxing the hundredth byte uses no more memory than boxing the first. For char/short/int/long, the memory use matters quite a bit more — in particular, anyone working with non-ASCII text and repeatedly boxing into Character is going to be pretty wildly unhappy. But yeah, the upshot is that having an Integer field instead of an int field can be a serious memory hit — 5x on a 32-bit machine (4 byte pointer, 16 byte allocation), 8x if you're on a 64-bit machine (8 byte pointer, 24 byte allocation) — if you fall outside of the cache range.
|
# ? Dec 5, 2012 03:29 |
|
Suspicious Dish posted:The auto-boxing makes it possible for the optimizer to inline these so that a "Byte" is just in a register, no? I don't know the Java calling convention, but I would guess that passing or returning a primitive byte or a boolean takes an entire register (if any are still available) or a word-sized segment of stack (otherwise). But temporary stack/register usage isn't really the important thing here; it's how much space it requires in an object or array. In both cases, it'd require some serious heroics for the optimizer to figure out that it can store a primitive instead of a boxed value, because code can intentionally make non-cached boxed values and rely on the reference inequality, so you'd have to prove that either the sinks of the reference are all address-invariant or that the sources are all guaranteed cached.
|
# ? Dec 5, 2012 03:37 |
|
Aleksei Vasiliev posted:Wait, you're saying that Java shouldn't have exposed primitives and complaining about memory usage of the object versions? The horror is violated expectations, not the memory usage itself. It just feels inconsistent for Java to be a bloated memory-wasting machine except for numbers under 128, and inconsistent for a special class of non-objects. I would rather the padded walls be complete and total. I suppose I'm a bit of a purist. And even if everything is an object and there's no such thing as a primitive, there's nothing stopping the VM from figuring out how to optimize an Integer into an int behind the scenes rather than having it happen by hand.
|
# ? Dec 5, 2012 08:48 |
|
"There's nothing stopping the VM from <insert arbitrarily complex program transformation>" is one of those things language implementors love to hear from people who clearly haven't thought much about the problem and know nothing about the constraints on the VM. The deep language problem is that Java can't do any useful abstraction over non-objects; any sort of generic treatment of values forces boxing. But unlike a dynamically-typed language, you can't reasonably optimize the representation of Object to make boxing cheaper — boxed ints aren't nearly common enough for that to pay off. So you have to trust the programmer to know when boxing really matters to their performance and avoid it.
|
# ? Dec 5, 2012 10:14 |
|
Doctor w-rw-rw- posted:The horror is violated expectations, not the memory usage itself. It just feels inconsistent for Java to be a bloated memory-wasting machine except for numbers under 128, and inconsistent for a special class of non-objects. I would rather the padded walls be complete and total. I suppose I'm a bit of a purist. And even if everything is an object and there's no such thing as a primitive, there's nothing stopping the VM from figuring out how to optimize an Integer into an int behind the scenes rather than having it happen by hand. If you're using Integers in a manner which would typically require the creation of a new object (hashcodes, reference equality, polymorphism, null values) and depending on primitive performance not in any contract, I'm not sure what you're looking for. What are they supposed to say? "Sure there's an obvious optimization which is such low hanging fruit that it's hovering at the very threshold of the gates of Hell, but we're going to leave it to you to decide whether it's worth it." The problem is more the behavior than it is the performance. Any situation where a boxed primitive can plausibly be stored directly in a stack frame, Java 1.7 and above will do that instead. Having two options may have made sense in 1996, but now it's straightforward to optimize out those cases. The subtly different semantics are the real issue.
|
# ? Dec 5, 2012 10:17 |
|
1337JiveTurkey posted:If you're using Integers in a manner which would typically require the creation of a new object (hashcodes, reference equality, polymorphism, null values) and depending on primitive performance not in any contract, I'm not sure what you're looking for. What are they supposed to say? "Sure there's an obvious optimization which is such low hanging fruit that it's hovering at the very threshold of the gates of Hell, but we're going to leave it to you to decide whether it's worth it." Are you arguing with me? Because I agree completely with exactly what you just said.
|
# ? Dec 5, 2012 12:07 |
|
They're a security consultant. Also, to top it off, they do hash their passwords... with a single, unsalted md5... before sending it to the API... which is public... and doesn't escape either the username or password before running them in an SQL statement. Not that it really matters, because none of the rest of the API requires authentication either, and you could get past the login screen just by calling the right JS function.
|
# ? Dec 5, 2012 13:08 |
|
bobthecheese posted:
There surely has to be a level where "calling yourself a security consultant" becomes "committing fraud".
|
# ? Dec 5, 2012 13:18 |
|
Doctor w-rw-rw- posted:Are you arguing with me? Because I agree completely with exactly what you just said. Calling Java's inability to offer performance guarantees on Integers a coding horror is a stretch of the term at best, especially in light of the capabilities of 15 year old embedded processors. It's a plausible decision for someone who doesn't know that client-side Java on internet toasters and JavaCards is a dream at best. It's still possible to be wrong by being way too conservative in retrospect without being a horror which is basically Java's longstanding problem. I reserve the term horror for languages like PHP where there often simply isn't a good reason at all and it's clear that it wasn't thought out and not Java where there's usually a reason but it might not have been the best one in light of experience.
|
# ? Dec 5, 2012 15:03 |
|
Mesothelioma posted:Every time I look at my buddy's methods he ALWAYS returns the object Boolean instead of a regular boolean. When I ask him why he uses the object instead of the primitive he stares blankly at me. Personally I prefer typing lower case names for types such as string, bool and such myself too, though, it just looks weird otherwise.
|
# ? Dec 5, 2012 16:24 |
|
|
# ? May 30, 2024 13:55 |
|
rjmccall posted:In both cases, it'd require some serious heroics for the optimizer to figure out that it can store a primitive instead of a boxed value, because code can intentionally make non-cached boxed values and rely on the reference inequality, so you'd have to prove that either the sinks of the reference are all address-invariant or that the sources are all guaranteed cached. Ah right; I didn't think of that. The reference semantics are extremely awkward for these pseudoprimitives.
|
# ? Dec 5, 2012 17:30 |