Submit

Back to the channels

#primate

  1. blue dreamreal: https://dpaste.com/967MYB5BR
  2. jreicher blue: what is that?
  3. blue jreicher: a demonstration of why I dislike java
  4. jreicher Because you used Integer rather than int and you think it should mean the same thing?
  5. blue jreicher: no, because == behaves unexpectedly, even for java. the first comparison is true, the second is false
  6. blue it's bad enough that == checks for identity, but it's even worse that it does not at least behave consistently
  7. jreicher == is behaving there exactly as it's defined for Integer. The definition is different for int. It has nothing to do with the language.
  8. blue obviously I'm not alone in thinking that, otherwise JEP 401 weren't a thing
  9. blue and java doing some kind of object caching for -128 to 127 is the very definition of dumb
  10. jreicher What object caching are you talking about?
  11. blue in the example I provided, the compiler outputs true, then false
  12. blue ie, n1 == n2 (with the values of 127) is true, whilst n3 == n4 is false
  13. blue https://docs.oracle.com/javase/specs/jls/se21/html/jls-5.html
  14. nevet Chapter 5. Conversions and Contexts
  15. blue "If the value p being boxed is the result of evaluating a constant expression (§15.29) of type boolean, byte, char, short, int, or long, and the result is true, false, a character in the range '\u0000' to '\u007f' inclusive, or an integer in the range -128 to 127 inclusive, then let a and b be the results of any two boxing conversions of p. It is always the case that a == b."
  16. jreicher blue: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Integer.html#valueOf(int)
  17. nevet Integer (Java SE 21 & JDK 21)
  18. jreicher "This method will always cache values in the range -128 to 127, inclusive, and may cache other values outside of this range."
  19. jreicher So again, it's the definition of that specific method, and nothing to do with the language
  20. blue how does the distinction matter? Integer.valueOf is very much an inherent part of the language, it's not like it's a third-party library
  21. blue I mean, Integer is java.lang.Integer
  22. jreicher Fair, I'm not going to argue the distinction. I'm just trying to point out that it's in the definition of one very specific part of the language/jdk. it's not like this is a design principle that extends throughout the entire language. And that one tiny corner is behaving exactly as it's defined.
  23. blue I'm not arguing that something isn't working as designed, jreicher. My point is the design is faulty, not just of this, but generally of the == operator comparing by identity. And the java language design process itself seems to have reached the same conclusion (only needing 30 years?), otherwise we wouldn't have JEP 401
  24. blue of course I find it deeply regrettable that JEP 401 won't extend to strings, but that's life, can't have it all
  25. jreicher I'm not arguing with you about the faultiness of the design, but the extent of it. You're making a claim about valueOf(). Is it faulty? Perhaps? Does that mean "the language is faulty"? That's nonsense.
  26. jreicher Put another way, if you want to make a claim about ==, then pick an example that doesn't depend on a quirk of just one method.
  27. blue the claim is easily abstractable: if something is inherently immutable, such as strings, then it is faulty to compare it by identity
  28. blue strings are my biggest pet pieve
  29. jreicher I agree, that's an easy to understand claim. I see no reason to believe it's true though IN GENERAL. I could have a very complex object that, although being immutable, is quite impractical to have an equality test in any way other than identity.
  30. jreicher https://en.wikipedia.org/wiki/Graph_isomorphism_problem
  31. nevet Graph isomorphism problem - Wikipedia
  32. jreicher For example
  33. blue that may be the case, but is it the *common* case? i.e., is this more important than the usefulness of string comparison by == ?
  34. blue other languages have mechanism for explicit identity comparison, like === in javascript
  35. blue mechanisms*
  36. jreicher I'm fairly sure I will be sympathetic to all the cases you want to call "common" for the purposes of being cases that i will be sympathetic to.
  37. jreicher The point is that your claim is much harder in general.
  38. jreicher And so I reject that it's a claim about the entire language. That still makes very little sense.
  39. blue I do not mean to reject the entire language on account of those faults. But they are massive faults in my eyes, and very annoying pet pieves. The best way to express it from my position is that java is not low-level enough to justify a c-like/rust/zig strcmp, but String#equals is in fact exactly that. Expressed differently: at the abstraction level that java is -- no manual memory management -- my
  40. blue expectation is for the == operator to work as expected (by which I mean a general programming, c-inherited expectation)
  41. blue the combination of a higher-level language and low-level gotchas is terrible
  42. blue and this *is* a gotcha. it cannot be argued away by "learn the language better". A language is primarily judged on ergonomics, expectation management, and ease of understanding. I do not need to under the java object model to use == on two strings, that's an expectation mismatch
  43. blue s/under/understand/
  44. jreicher Of you expect == to be what you expect, because you came to Java prejudiced with your expectation. I'm asking you to justify that expectation rather than keep putting forward this circular argument.
  45. jreicher Why SHOULD == work that way? What's wrong with object identity for complex objects?
  46. blue and I just did: java is not low-level enough to justify a strcmp instead of ==
  47. jreicher The burden of proof is the other way. You need to justify your expectation.
  48. blue there's nothing wrong; but working with strings is by far and wide the more common case than working with complex (immutable, so rarer still) objects you need to compare
  49. jreicher I already said I would be sympathetic to the common cases, but you keep trying to make a claim about == in general.
  50. jreicher If you restrict what you are saying to just the definition of == for String, we won't have an argument.
  51. blue but that *is* my point. I want == to generally work for strings, integers, and anything else that, for lack of a better umbrella term, I put under "immutable", as in representing a concrete value that's unchangeable without reassignment. You seem to take issue with some (as far as I'm concerned) corner case of complex immutable objects?
  52. jreicher You don't get to say "I want to change the behaviour for String, and I want to achieve that by changing the behaviour for EVERYTHING". That's maddeningly silly. Why can't you see that? You're either talking about String, or your'e talking about everything. If the former, restrain yourself. If the latter, justify it properly.
  53. blue I already did; == should compare by value for immutables, by identity otherwise (mostly custom objects) -- this is the javascript behaviour. Additionally, there should be an explicit === operator or just the java #equalsTo method, if you explicitly want to enforce "by identity"
  54. jreicher I'll offer you a better category: immutable scalars. That's probably what you really mean.
  55. jreicher So complex immutable objects don't owe you anything.
  56. blue hm, unsure. What about two sets that both contain [2, 3] ?
  57. jreicher Exactly.
  58. blue you really want to compare them by identity? is that meaningful? I don't think so
  59. jreicher You really want to compare them with value equality? You sure that's reasonable?
  60. blue I think so. That's my mathematical understanding of sets, and tuples, and I find it good
  61. blue we could argue if it should be limited to immutable or mutable sets, but I find it good
  62. jreicher It's not a mathematical question. It's a computational one.
  63. blue but still I'd like to harp on th ecomplex immutable objects. Could you explain *why* it makes sense to compare them by identity? they're unchangeable post-construction, so what benefit does the identity comparison hold?
  64. jreicher I just did. Consider the computation of doing value equality. A set with a million elements should do the trick as an example.
  65. blue isn't that an implementation detail though?
  66. jreicher The implementation has to satisfy the contract, and conversely the contract can't be something that's impossible to implement. So consider the contract carefully. You're the one who is preoccupied with programmer expectation, and I think you are right.
  67. blue I'd be remiss to not remind here that the tuples & records proposal for javascript (tuples would be immutable arrays, records immutable objects) wasn't rejected on account of computational complexity, but on account of browser makers not wanting to have additional primitives in the language, due to bad past experience in the introduction of bigint
  68. jreicher tuples and records are different to sets.
  69. blue I'm pretty sure that an array comparison of millions of elements presents a similar, if not higher challenge (sets are generally unordered), than sets?
  70. jreicher Probably, yes, but I don't think that's the same as a tuple or record either.
  71. blue just to be clear here, since the terms are terribly overloaded in CS. a 'tuple' in the proposal would have been the exact same thing as a JS array, with the exception that it would be immutable, and its comparisons would be by value(s). And 'record', the same, for JS objects
  72. blue by which term I don't mean any JS object, but a classic dictionary object, {}
  73. blue hash map/associative array/whatever other name CS has for it
  74. jreicher I don't take tuples to be the same as a JS array
  75. blue in the proposal, they were. I'm strictly speaking of how the proposal defined them
  76. jreicher Are you sure?
  77. jreicher Why have a new type identical to something that already exists?
  78. blue because immutability is great
  79. blue array: [], tuple: #[] (as per the proposal)
  80. jreicher And what do you think immutability would do to the use of the array?
  81. blue well, as per the proposal, nothing, arrays would stay the same
  82. blue [1, 2] == [1, 2], false
  83. jreicher If the "array" (tuple) is immutable, it means you can only set the elements at initialisation, right?
  84. blue #[1, 2] == #[1, 2], true
  85. blue yes
  86. jreicher So what do you think that does to the "array" (tuple)?
  87. blue intern it
  88. jreicher And?
  89. blue you're gonna argue it becomes a comparison by identity. but that supports exactly my point for Java!
  90. jreicher Not at all. Not even close.
  91. jreicher What's the initialisation syntax?
  92. blue #[1, 2]
  93. jreicher What would that look like for a tuple with a million elements?
  94. blue #[1, 2, ..., 1000**2]
  95. jreicher Do you think that would happen?
  96. blue surely. I can see you reading into stuff from fasta files into memory
  97. blue there are many use cases; conf files (as per the record syntax, immutable objects: #{}); read the conf once, then reread when it is saved, and now you have a reliable way to check if it actually changed
  98. jreicher Well I don't. I think the only reason "most people" consider tuples and records feasible candidates for value equality is that the literal addressing in source code of them has a natural limiting effect on their dimensionality. They are effectively scalars.
  99. jreicher They're tiny.
  100. blue what about vector equality in a coordination system (higher dimension)?
  101. blue coordinate system*
  102. jreicher Same. From a computational point of view it's effectively a scalar. But I don't really care about the terminology. What I care about is the scale. If you want to limit your complaint to small immutable objects, we don't have an argument. But if you want to make a general point you have to explain why it's reasonable for large complex objects.
  103. blue I'm not gonna die on the large complex objects hill. My point is ergonomics: if 90% of the use cases are covered, that's fine by me
  104. blue that being said, I would stand unopposed to an Object.same static method or so
  105. dreamreal blue: that paste is not why you dislike java
  106. dreamreal that behavior is documented and well-known and predictable *and* justifiable
  107. dreamreal dislike java if you like, justifying it is dumb
  108. dreamreal Integer equality is based on object equality, and new integers are allocated sparsely: the range from -127 to 127 is always going to get you the same integer object
  109. dreamreal apart from that, no
  110. dreamreal and as always you don't use == to compare *object equality* but only object *identity*
  111. dreamreal this is not a "oh use == for these objects but not these over here" situation
  112. dreamreal if you want object identity, use ==. If not, use equals(). That's it.
  113. dreamreal and there *are* instance methods for helping be more explicit.
  114. dreamreal but for SOME reason most java coders don't need them, being able to reason
  115. dreamreal was hoping there was soemthing worthwhile here
  116. jreicher Actually it might be worth considering the idea that == is object equality for primitive types too. It's just that they are very special objects.
  117. jreicher Sorry, I mean object identity!
  118. dreamreal Hmm, I wonder if java exposes the reference information for primitives like that
  119. dreamreal valhalla's going to mangle all of that, including the rules about integer allocation, I think
  120. dreamreal I haven't tried valhalla out yet: work's on java 17, with an intended migration to 25 later this quarter: when that happens we'll break the chains to old java versions (we're lucky we got 17 when we did) and THEN when valhalla gets to LTS we'll be able to try it out
  121. dreamreal but until it's LTS there's no point
  122. dreamreal we'll have to see if I last a work for that to happen :D
  123. dreamreal but shhhh that's not common knowledge
  124. jreicher Your work migrates to something when it's LTS? We normally do it when it's EOL.
  125. dreamreal We're apparently forward-thinking! haha
  126. dreamreal actually, the developers on the team said "screw this, we're not staying on 8"
  127. dreamreal and by the time the people who would have said "oh yes we are" had a choice we'd already migrated
  128. dreamreal there's a lot of political momentum involved, part of why I might move on
  129. jreicher Ah, the good old mutinous developers strategy
  130. dreamreal I was shouting for 21, but 17 won (installation rules won) and now we have release to move to 25, it's just a drag to move the toolchain
  131. dreamreal and we have bigger problems
  132. blue dreamreal: -128 to 127, you mean!
  133. blue dreamreal: btw, we're on 21 (I think I told you). I got us there from... *drums* java 8.
  134. dreamreal blue: the actual range doesn't matter
  135. dreamreal and good
  136. dreamreal 21 is good
  137. blue I feel like my boss though will comfortable sit on 21 until it's literally cut away from under his feet, which is like, 2031
  138. dreamreal 17 is okay but 21 is far better
  139. blue of course, I personally want to go up to 25, because you know, wasm shenanigans
  140. blue not that we're gonna use that, but I just *like* 25 because it's wasmable
  141. * dreamreal refuses to point out cheerpj which can wasmify java 7
  142. dreamreal sorry, java 9
  143. dreamreal 8
  144. dreamreal damn it
  145. dreamreal 8
  146. blue btw; if anyone wants to have with a primate java backend, you're all cordially invited!
  147. dreamreal damn cat
  148. blue haha
  149. blue wants to help*
  150. dreamreal she's a lovely creature but wants my right hand
  151. blue there's a poc just awaiting for you (yes, looking at YOU) to make it a reality!
  152. blue https://github.com/primate-run/wasm/tree/master/java
  153. blue of course, that poc is just me running java in wasm, but hey, that's something!
  154. blue mostly I haven't explored that further because I'm lacking the mindset of what would be a good API for the routes
  155. blue everything I came up with seemed overengineered to me
  156. dreamreal That's unlikely to be avoided with java
  157. blue IOW, forcing users to write a class for every route file, seems like a nightmare
  158. blue iirc java 25 though has toplevel methods
  159. dreamreal it's pretty much the standard for Java
  160. dreamreal don't use them
  161. blue why not?
  162. dreamreal kotlin has them, but I would avoid them here
  163. dreamreal idiom
  164. blue WHY
  165. dreamreal everyone would look at primate and say "okay it has java" and use spring or quarkus instead
  166. dreamreal they use annotations for methods to establish routes
  167. blue import static primate.Route.*; void main() { get(request -> "Hello from Java"); }
  168. blue that's good, no?
  169. dreamreal it's very easy, very convenient, and is a standard now
  170. dreamreal it's also insufficient for anything but a toy
  171. dreamreal but do as you wish, see what happens, if I wa sthe one to build the better mousetrap I'd have done it already
  172. blue I don't need to reinvent spring though
  173. dreamreal nobody does
  174. blue I need a good wasm backend for primate
  175. dreamreal and vert.x and quarkus and others don't
  176. blue what's wrong with the snippet I just examplified?
  177. dreamreal it's very short, and gives no hint to context or routes or parameters or any other routes
  178. blue routes are filesystem based, you know that
  179. dreamreal and the thing about classes being in files is that it makes them very easy to *find*
  180. dreamreal yes, and you'd be swimming against 30 years of java convention
  181. dreamreal IBM tried that
  182. blue you have to flip the mindset. I'm not trying to convince JAVA users. I'm convincing primate users who might need to use a Java lib! that's a different value proposition
  183. dreamreal sure, and I'm not the one who can speak to them
  184. blue I don't need to go up against spring or vert.x or quarkus or whoever's the new kid on the block, because I don't care about them; I can about making most of the java ecosystem integratable to a primate application
  185. blue that's a whole different ball game!
  186. dreamreal Sure
  187. blue also, unrelated, there's a dude who wants to work with me on flog
  188. blue he proposed the original version: make the *engine* interchangable
  189. blue this was my original idea before I decided it was too much work for one person

Search posts