Chat Logs

  1. * jreicher joined #primate
  2. * skillnews joined #primate
  3. * skillbot joined #primate
  4. bluedreamreal: https://dpaste.com/967MYB5BR
  5. jreicherblue: what is that?
  6. bluejreicher: a demonstration of why I dislike java
  7. jreicherBecause you used Integer rather than int and you think it should mean the same thing?
  8. bluejreicher: no, because == behaves unexpectedly, even for java. the first comparison is true, the second is false
  9. blueit's bad enough that == checks for identity, but it's even worse that it does not at least behave consistently
  10. 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.
  11. blueobviously I'm not alone in thinking that, otherwise JEP 401 weren't a thing
  12. blueand java doing some kind of object caching for -128 to 127 is the very definition of dumb
  13. jreicherWhat object caching are you talking about?
  14. bluein the example I provided, the compiler outputs true, then false
  15. blueie, n1 == n2 (with the values of 127) is true, whilst n3 == n4 is false
  16. bluehttps://docs.oracle.com/javase/specs/jls/se21/html/jls-5.html
  17. nevetChapter 5. Conversions and Contexts
  18. 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."
  19. jreicherblue: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Integer.html#valueOf(int)
  20. nevetInteger (Java SE 21 & JDK 21)
  21. jreicher"This method will always cache values in the range -128 to 127, inclusive, and may cache other values outside of this range."
  22. jreicherSo again, it's the definition of that specific method, and nothing to do with the language
  23. bluehow 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
  24. blueI mean, Integer is java.lang.Integer
  25. jreicherFair, 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.
  26. blueI'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
  27. blueof course I find it deeply regrettable that JEP 401 won't extend to strings, but that's life, can't have it all
  28. jreicherI'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.
  29. jreicherPut 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.
  30. bluethe claim is easily abstractable: if something is inherently immutable, such as strings, then it is faulty to compare it by identity
  31. bluestrings are my biggest pet pieve
  32. jreicherI 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.
  33. jreicherhttps://en.wikipedia.org/wiki/Graph_isomorphism_problem
  34. nevetGraph isomorphism problem - Wikipedia
  35. jreicherFor example
  36. bluethat may be the case, but is it the *common* case? i.e., is this more important than the usefulness of string comparison by == ?
  37. blueother languages have mechanism for explicit identity comparison, like === in javascript
  38. bluemechanisms*
  39. jreicherI'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.
  40. jreicherThe point is that your claim is much harder in general.
  41. jreicherAnd so I reject that it's a claim about the entire language. That still makes very little sense.
  42. blueI 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
  43. blueexpectation is for the == operator to work as expected (by which I mean a general programming, c-inherited expectation)
  44. bluethe combination of a higher-level language and low-level gotchas is terrible
  45. blueand 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
  46. blues/under/understand/
  47. jreicherOf 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.
  48. jreicherWhy SHOULD == work that way? What's wrong with object identity for complex objects?
  49. blueand I just did: java is not low-level enough to justify a strcmp instead of ==
  50. jreicherThe burden of proof is the other way. You need to justify your expectation.
  51. bluethere'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
  52. jreicherI already said I would be sympathetic to the common cases, but you keep trying to make a claim about == in general.
  53. jreicherIf you restrict what you are saying to just the definition of == for String, we won't have an argument.
  54. bluebut 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?
  55. jreicherYou 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.
  56. blueI 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"
  57. jreicherI'll offer you a better category: immutable scalars. That's probably what you really mean.
  58. jreicherSo complex immutable objects don't owe you anything.
  59. bluehm, unsure. What about two sets that both contain [2, 3] ?
  60. jreicherExactly.
  61. blueyou really want to compare them by identity? is that meaningful? I don't think so
  62. jreicherYou really want to compare them with value equality? You sure that's reasonable?
  63. blueI think so. That's my mathematical understanding of sets, and tuples, and I find it good
  64. bluewe could argue if it should be limited to immutable or mutable sets, but I find it good
  65. jreicherIt's not a mathematical question. It's a computational one.
  66. bluebut 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?
  67. jreicherI just did. Consider the computation of doing value equality. A set with a million elements should do the trick as an example.
  68. blueisn't that an implementation detail though?
  69. jreicherThe 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.
  70. blueI'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
  71. jreichertuples and records are different to sets.
  72. blueI'm pretty sure that an array comparison of millions of elements presents a similar, if not higher challenge (sets are generally unordered), than sets?
  73. jreicherProbably, yes, but I don't think that's the same as a tuple or record either.
  74. bluejust 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
  75. blueby which term I don't mean any JS object, but a classic dictionary object, {}
  76. bluehash map/associative array/whatever other name CS has for it
  77. jreicherI don't take tuples to be the same as a JS array
  78. bluein the proposal, they were. I'm strictly speaking of how the proposal defined them
  79. jreicherAre you sure?
  80. jreicherWhy have a new type identical to something that already exists?
  81. bluebecause immutability is great
  82. bluearray: [], tuple: #[] (as per the proposal)
  83. jreicherAnd what do you think immutability would do to the use of the array?
  84. bluewell, as per the proposal, nothing, arrays would stay the same
  85. blue[1, 2] == [1, 2], false
  86. jreicherIf the "array" (tuple) is immutable, it means you can only set the elements at initialisation, right?
  87. blue#[1, 2] == #[1, 2], true
  88. blueyes
  89. jreicherSo what do you think that does to the "array" (tuple)?
  90. blueintern it
  91. jreicherAnd?
  92. blueyou're gonna argue it becomes a comparison by identity. but that supports exactly my point for Java!
  93. jreicherNot at all. Not even close.
  94. jreicherWhat's the initialisation syntax?
  95. blue#[1, 2]
  96. jreicherWhat would that look like for a tuple with a million elements?
  97. blue#[1, 2, ..., 1000**2]
  98. jreicherDo you think that would happen?
  99. bluesurely. I can see you reading into stuff from fasta files into memory
  100. bluethere 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
  101. jreicherWell 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.
  102. jreicherThey're tiny.
  103. bluewhat about vector equality in a coordination system (higher dimension)?
  104. bluecoordinate system*
  105. jreicherSame. 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.
  106. blueI'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
  107. bluethat being said, I would stand unopposed to an Object.same static method or so
  108. dreamrealblue: that paste is not why you dislike java
  109. dreamrealthat behavior is documented and well-known and predictable *and* justifiable
  110. dreamrealdislike java if you like, justifying it is dumb
  111. dreamrealInteger 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
  112. dreamrealapart from that, no
  113. dreamrealand as always you don't use == to compare *object equality* but only object *identity*
  114. dreamrealthis is not a "oh use == for these objects but not these over here" situation
  115. dreamrealif you want object identity, use ==. If not, use equals(). That's it.
  116. dreamrealand there *are* instance methods for helping be more explicit.
  117. dreamrealbut for SOME reason most java coders don't need them, being able to reason
  118. dreamrealwas hoping there was soemthing worthwhile here
  119. jreicherActually it might be worth considering the idea that == is object equality for primitive types too. It's just that they are very special objects.
  120. jreicherSorry, I mean object identity!
  121. dreamrealHmm, I wonder if java exposes the reference information for primitives like that
  122. dreamrealvalhalla's going to mangle all of that, including the rules about integer allocation, I think
  123. dreamrealI 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
  124. dreamrealbut until it's LTS there's no point
  125. dreamrealwe'll have to see if I last a work for that to happen :D
  126. dreamrealbut shhhh that's not common knowledge
  127. jreicherYour work migrates to something when it's LTS? We normally do it when it's EOL.
  128. dreamrealWe're apparently forward-thinking! haha
  129. dreamrealactually, the developers on the team said "screw this, we're not staying on 8"
  130. dreamrealand by the time the people who would have said "oh yes we are" had a choice we'd already migrated
  131. dreamrealthere's a lot of political momentum involved, part of why I might move on
  132. jreicherAh, the good old mutinous developers strategy
  133. dreamrealI 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
  134. dreamrealand we have bigger problems
  135. bluedreamreal: -128 to 127, you mean!
  136. bluedreamreal: btw, we're on 21 (I think I told you). I got us there from... *drums* java 8.
  137. dreamrealblue: the actual range doesn't matter
  138. dreamrealand good
  139. dreamreal21 is good
  140. blueI feel like my boss though will comfortable sit on 21 until it's literally cut away from under his feet, which is like, 2031
  141. dreamreal17 is okay but 21 is far better
  142. blueof course, I personally want to go up to 25, because you know, wasm shenanigans
  143. bluenot that we're gonna use that, but I just *like* 25 because it's wasmable
  144. * dreamreal refuses to point out cheerpj which can wasmify java 7
  145. dreamrealsorry, java 9
  146. dreamreal8
  147. dreamrealdamn it
  148. dreamreal8
  149. bluebtw; if anyone wants to have with a primate java backend, you're all cordially invited!
  150. dreamrealdamn cat
  151. bluehaha
  152. bluewants to help*
  153. dreamrealshe's a lovely creature but wants my right hand
  154. bluethere's a poc just awaiting for you (yes, looking at YOU) to make it a reality!
  155. bluehttps://github.com/primate-run/wasm/tree/master/java
  156. blueof course, that poc is just me running java in wasm, but hey, that's something!
  157. bluemostly I haven't explored that further because I'm lacking the mindset of what would be a good API for the routes
  158. blueeverything I came up with seemed overengineered to me
  159. dreamrealThat's unlikely to be avoided with java
  160. blueIOW, forcing users to write a class for every route file, seems like a nightmare
  161. blueiirc java 25 though has toplevel methods
  162. dreamrealit's pretty much the standard for Java
  163. dreamrealdon't use them
  164. bluewhy not?
  165. dreamrealkotlin has them, but I would avoid them here
  166. dreamrealidiom
  167. blueWHY
  168. dreamrealeveryone would look at primate and say "okay it has java" and use spring or quarkus instead
  169. dreamrealthey use annotations for methods to establish routes
  170. blueimport static primate.Route.*; void main() { get(request -> "Hello from Java"); }
  171. bluethat's good, no?
  172. dreamrealit's very easy, very convenient, and is a standard now
  173. dreamrealit's also insufficient for anything but a toy
  174. dreamrealbut do as you wish, see what happens, if I wa sthe one to build the better mousetrap I'd have done it already
  175. blueI don't need to reinvent spring though
  176. dreamrealnobody does
  177. blueI need a good wasm backend for primate
  178. dreamrealand vert.x and quarkus and others don't
  179. bluewhat's wrong with the snippet I just examplified?
  180. dreamrealit's very short, and gives no hint to context or routes or parameters or any other routes
  181. blueroutes are filesystem based, you know that
  182. dreamrealand the thing about classes being in files is that it makes them very easy to *find*
  183. dreamrealyes, and you'd be swimming against 30 years of java convention
  184. dreamrealIBM tried that
  185. blueyou 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
  186. dreamrealsure, and I'm not the one who can speak to them
  187. blueI 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
  188. bluethat's a whole different ball game!
  189. dreamrealSure
  190. bluealso, unrelated, there's a dude who wants to work with me on flog
  191. bluehe proposed the original version: make the *engine* interchangable
  192. bluethis was my original idea before I decided it was too much work for one person
  193. * skillnews joined #primate
  194. * skillbot joined #primate
  195. * skillnews joined #primate
  196. * skillbot joined #primate
  197. * skillbot joined #primate
  198. * skillnews joined #primate
  199. * skillnews joined #primate
  200. * skillbot joined #primate
  201. * skillbot joined #primate
  202. * skillnews joined #primate
  203. * skillnews joined #primate
  204. * skillbot joined #primate
  205. * skillbot joined #primate
  206. * skillbot joined #primate
  207. * skillnews joined #primate
  208. * skillnews joined #primate
  209. * skillbot joined #primate
  210. * skillnews joined #primate