|
Just lol at the idea that treating < 0 size lists like 0 size lists is defensive programming.
|
# ? May 15, 2019 20:16 |
|
|
# ? Jun 27, 2024 17:26 |
|
Opferwurst posted:it's what happens when you use some ReSharper auto refactoring functionality. It inverts a ">0" statement, but isn't smart enough to know that arrays can't have a negative size. I feel like there are quite a few seeming coding horrors born out of refactoring operations like this.
|
# ? May 15, 2019 20:34 |
|
AstuteCat posted:Depending on language/implementation, In some cases calling a count() will traverse the list to get the count - if you're trying to see if an enum/list is non-empty, doing an equivalent of 'list != []' might be quicker. Out of wonder, which languages? The only one I know of is C strings, I wasn't aware that some (modern) languages didn't just keep an associated count variable.
|
# ? May 15, 2019 22:37 |
|
Linear Zoetrope posted:Out of wonder, which languages? The only one I know of is C strings, I wasn't aware that some (modern) languages didn't just keep an associated count variable. Lists in languages like Haskell and ML have this property. It’s common in functional cases where there isn’t really any concept of a list as a distinct object that you could store a length field in. If you allow collections in general rather than just lists then there are even some examples in the Java standard library - ConcurrentSkipListSet, for example.
|
# ? May 15, 2019 22:46 |
|
Linear Zoetrope posted:Out of wonder, which languages? The only one I know of is C strings, I wasn't aware that some (modern) languages didn't just keep an associated count variable. LINQ extends everything enumerable with a Count() method. Mixing up list.Count and list.Count() can have huge performance implications in C#.
|
# ? May 15, 2019 23:12 |
|
Opferwurst posted:LINQ extends everything enumerable with a Count() method. Mixing up list.Count and list.Count() can have huge performance implications in C#. What's actually bad is having an IEnumerable-only type and using if (sequence.Count() > 0) instead of if (sequence.Any()).
|
# ? May 15, 2019 23:52 |
|
Ah yeah, I was stuck on plain array-backed collections and didn't think about functional languages, recursive types, or odd cases like skip lists which are all kind of obvious cases. (Though in the case of things like Haskell can't the compiler sometimes compile-away the count in optimizations?)
|
# ? May 16, 2019 00:00 |
|
Linear Zoetrope posted:Ah yeah, I was stuck on plain array-backed collections and didn't think about functional languages, recursive types, or odd cases like skip lists which are all kind of obvious cases. (Though in the case of things like Haskell can't the compiler sometimes compile-away the count in optimizations?) In Haskell you wouldn't use length to check if a list was empty
|
# ? May 16, 2019 00:19 |
|
If you compute the length of a list in Haskell you're probably doing something wrong.
|
# ? May 16, 2019 00:55 |
|
DaTroof posted:fencepost error Thank you for this term. Every random integer implementation is a crapshoot on this.
|
# ? May 16, 2019 01:16 |
|
ultrafilter posted:If you compute the length of a list in Haskell you're probably doing something wrong. Gosh, imagine needing to know how many things you have in a collection.
|
# ? May 16, 2019 02:43 |
|
redleader posted:Gosh, imagine needing to know how many things you have in a collection. That would be knowledge of state and such knowledge IS FORBIDDEN AND AN AFFRONT TO THE CURRY. The Curry will only accept an O(n), recursive, list traversing element counter.
|
# ? May 16, 2019 07:00 |
redleader posted:Gosh, imagine needing to know how many things you have in a collection. Haskell "lists" should be thought of and used as stacks, or else you probably want a different data structure. And for the most part you don't need to know how many elements are in a stack; you just need to know if there are any elements left. In the cases where you do care it would be pretty trivial to write a wrapper datatype that kept track of the size. Also, I ran into this horror today: code:
|
|
# ? May 16, 2019 07:21 |
|
VikingofRock posted:Also, I ran into this horror today: It took me a while to see this, as my brain refused to believe that someone would do this.
|
# ? May 16, 2019 07:30 |
|
Does the entire situation with constexpr in C++ count as a coding horror? Tried to make a compile time string hasher, using it to store the hash of whatever string in a class, however unless it was called through constexpr variables, it would not get evaluated as constexpr in any useful scenario (these are constant, compile time strings, so it should work). End result, I have to manually store the value into a constexpr variable before assigning it to the field in the class. Yes, I know C++20 adds consteval but it's still dumb.
|
# ? May 16, 2019 08:56 |
Falcorum posted:Does [...] C++ count as a coding horror?
|
|
# ? May 16, 2019 11:51 |
|
code:
|
# ? May 18, 2019 12:07 |
|
NihilCredo posted:
To debug the butt, you must become the butt.
|
# ? May 18, 2019 12:43 |
|
NihilCredo posted:
What are we supposed to be looking for here
|
# ? May 18, 2019 14:01 |
|
Hammerite posted:What are we supposed to be looking for here Context: it was used by a coder who didn't understand the concept of references, so instead of doing: code:
code:
|
# ? May 18, 2019 14:52 |
|
NihilCredo posted:Context: it was used by a coder who didn't understand the concept of references, so instead of doing: Oh I see. Yeah that's not ok, you need to at least have a basic understanding of the object reference model for the language you're working in, or you're going to write all kinds of bugs and un-idiomatic code. e: "you" is used generically.
|
# ? May 18, 2019 15:00 |
|
Hammerite posted:e: "you" is used generically.
|
# ? May 18, 2019 15:40 |
Sagacity posted:Are you saying it doesn't apply to golang? trying to write idiomatic go was your first mistake
|
|
# ? May 18, 2019 17:54 |
|
Jazerus posted:trying to write
|
# ? May 18, 2019 18:38 |
|
|
# ? May 18, 2019 19:00 |
|
idiotmatic
|
# ? May 19, 2019 04:19 |
|
Eggnogium posted:Just lol at the idea that treating < 0 size lists like 0 size lists is defensive programming. To be fair I don't think people were specifically referring to <=0 sized list, just the general notion that when checking for a non-positive integer <= 0 is a common defensive practice even when there's no expectation that N will be less than 0. People weren't trying to excuse this usage but just offering explanations as to the thinking that led to the mistake. That was my interpretation anyway.
|
# ? May 19, 2019 10:34 |
|
Just use unsigned ints like the machine spirit intended.
|
# ? May 19, 2019 19:23 |
|
Falcorum posted:Just use unsigned ints like the machine spirit intended.
|
# ? May 19, 2019 19:31 |
|
Falcorum posted:Just use unsigned ints like the machine spirit intended.
|
# ? May 19, 2019 19:32 |
|
Falcorum posted:Just use unassigned ints like the machine spirit intended.
|
# ? May 19, 2019 19:38 |
|
Just use floating point array sizes and indices, embrace the webdev future Plus it’s useful if you only want to add half an object to the array
|
# ? May 19, 2019 20:00 |
|
Falcorum posted:Just use unsigned ints like the machine spirit intended. the only true path is to have your only numeric type be a double-precision 64-bit binary format IEEE 754 value. dividing by zero shall set this value to a type "Infinite" instead of throwing an exception, and obviously doing a for loop from 0 to infinite shall cause a hang, and performing any arithmetic operation with an undefined value shall silently convert said value to NaN, as god intended. Drawing something to canvas? Behold as you iterate through your data structure that is filled with NaN and the draw calls all work, as obviously the correct response to being told to draw with the coordinates being NaN is to just do nothing, rather than daring to throw an exception as that might make the V8 engine perform poorly.
|
# ? May 19, 2019 20:03 |
|
Bruegels Fuckbooks posted:the only true path is to have your only numeric type be a double-precision 64-bit binary format IEEE 754 value. dividing by zero shall set this value to a type "Infinite" instead of throwing an exception, and obviously doing a for loop from 0 to infinite shall cause a hang, and performing any arithmetic operation with an undefined value shall silently convert said value to NaN, as god intended. Drawing something to canvas? Behold as you iterate through your data structure that is filled with NaN and the draw calls all work, as obviously the correct response to being told to draw with the coordinates being NaN is to just do nothing, rather than daring to throw an exception as that might make the V8 engine perform poorly. Ah, the OpenGL school of error handling.
|
# ? May 19, 2019 20:05 |
|
Soricidus posted:Just use floating point array sizes and indices, embrace the webdev future Also if you want an array with a quintillion elements (though, not if you want to address all of them)
|
# ? May 19, 2019 20:57 |
|
Soricidus posted:Just use floating point array sizes and indices, embrace the webdev future the webdev future is webassembly (I say, hoping and praying)
|
# ? May 19, 2019 21:34 |
|
Absurd Alhazred posted:Ah, the OpenGL school of error handling. I was gonna say Pascal with range checking disabled
|
# ? May 20, 2019 01:49 |
|
https://twitter.com/QuinnyPig/status/1128056939470917632
|
# ? May 20, 2019 04:56 |
|
Falcorum posted:Just use unsigned ints like the machine spirit intended. But the compiler generates better code with signed ints. Because it is allowed to assume that signed overflows don't happen. I still use unsigned for sizes of things, though.
|
# ? May 20, 2019 06:09 |
|
|
# ? Jun 27, 2024 17:26 |
|
Zopotantor posted:But the compiler generates better code with signed ints. Because it is allowed to assume that signed overflows don't happen. I still use unsigned for sizes of things, though. I live in the blessed land of GC and exceptions. I thought that unsigned overflow was simply the codification of what would happen by default anyway if unsigned overflow were left as UB. Are there any architectures that need to specifically handle them because they would do weird things otherwise and not guarantee 255 + 2 = 1?
|
# ? May 20, 2019 09:02 |