|
ExcessBLarg! posted:I'm struggling to think of a good example of having 100+ "else if" blocks even for generated code. Surely it could be converted to some kind of dispatch mechanism, or at least convert the conditional tests into a tree form. if (opcode == FOO) { ... } else if (opcode == BAR) { ... } else if ... Yes, it can be trivially converted to other forms that don't run up against the limit, but there's no inherent reason you'd start there when something as simple as this is the lowest hanging fruit and adding in a dispatch mechanism isn't necessarily going to be good for performance.
|
# ? Dec 18, 2023 17:35 |
|
|
# ? Jun 1, 2024 05:00 |
|
ExcessBLarg! posted:I'm struggling to think of a good example of having 100+ "else if" blocks even for generated code. Surely it could be converted to some kind of dispatch mechanism, or at least convert the conditional tests into a tree form. Yes, I would expect the compiler to compile it efficiently, based on its knowledge of the target architecture. That's why I would generate C instead of machine code.
|
# ? Dec 18, 2023 17:43 |
|
Volte posted:if (opcode == FOO) { ... } else if (opcode == BAR) { ... } else if ... Athas posted:Yes, I would expect the compiler to compile it efficiently, based on its knowledge of the target architecture.
|
# ? Dec 18, 2023 18:34 |
|
ExcessBLarg! posted:This could trivially be written as switch/case even within a code generator.
|
# ? Dec 18, 2023 19:31 |
|
Volte posted:Nobody has argued that it's the only way to write it, just that it is a place where it could conceivably come up in a non-horror situation. Which is to say that the limitation itself may be defensible.
|
# ? Dec 18, 2023 19:56 |
|
I remember when the generated code for our most extremely complicated enum got so big that the bytecode for the static initializer no longer fit under the JVM limit and we had to retool things. (or something like that)
|
# ? Dec 18, 2023 20:17 |
|
I once worked with a C# library that generated database mapping code based on a model file. The generated code was full of lambda functions, and was all piled into a single method. With our oversized database model, the amount of lambdas in that file got so big that the method threw a StackOverflowException. It's still the only time I've seen a stack overflow that wasn't caused by recursion.
|
# ? Dec 18, 2023 22:21 |
|
ExcessBLarg! posted:To refine my earlier point, I'm struggling to think of an example of needing 100+ "else if" blocks that couldn't be written in a better (whether stylistic or performant) way. you have some pretty weird standards if you think 100 if-elses is bad but 100 switch cases is suddenly good / "better" it's all the same poo poo
|
# ? Dec 22, 2023 10:48 |
|
RPATDO_LAMD posted:you have some pretty weird standards if you think 100 if-elses is bad but 100 switch cases is suddenly good / "better" If 100 if-elses or switch cases need to select from one of 100 branches based on a single value, I'd rather represent those branches with a map of functions. But the more likely scenario is that the branches depend on multiple conditions that can be isolated into discrete components.
|
# ? Dec 22, 2023 11:56 |
|
In C and C++, switches only support direct comparisons of integral type. If-else chain can do whatever the gently caress it wants, and even have side effects in the conditions. 100 case switch is lot less scary than 100 checks in an if-else ladder
|
# ? Dec 22, 2023 13:58 |
|
RPATDO_LAMD posted:you have some pretty weird standards if you think 100 if-elses is bad but 100 switch cases is suddenly good / "better" switch with a lot of cases is easier to understand and debug than if/elseif with a lot of branches - hell i'd say the core of many emulators for cpus is just a giant switch statement - you put all the opcodes in the switch, if there are duplicate instructions you can group them up easily using labels, it's easy to deal with unimplemented opcodes using a default case rather than having to trace through the debugger trying every if statement.... even if the method is huge it's still easy to add opcodes to it if you find new ones etc. meanwhile 100 chained elsifs, the conditions are harder to read, it's harder to add new conditions, there's always the possibility that jimmy put logic in one of the conditions and made it that much harder to understand, and you have to read all the conditions and step through them all all to know if it's going to the "end" at the bottom of the method.
|
# ? Dec 22, 2023 17:59 |
|
None of which matters at all when the whole context is autogenerated interface glue code.
|
# ? Dec 22, 2023 21:09 |
|
EssOEss posted:None of which matters at all when the whole context is autogenerated interface glue code. Absolutely, there's that. If we're talking about generated code that no human should inspect unless they're debugging the generator itself, none of this matters
|
# ? Dec 23, 2023 01:21 |
|
Xarn posted:In C and C++, switches only support direct comparisons of integral type. If-else chain can do whatever the gently caress it wants, and even have side effects in the conditions. a language for cowards, unlike the chad java script: JavaScript code:
JavaScript code:
not sure what version of js you need for this to work. it works in the chrome and firefox consoles, but not on jsfiddle or in the typescript playground. you also have to use the comma operator (lol) - case { prop: value } = x && value >= 5: return value doesn't match, no doubt for reasons that you could consider logical in the context of brendan eich's masterpiece of language design. i'd dig more but i've already spent far too much time on this nonsense
|
# ? Dec 23, 2023 02:04 |
|
redleader posted:a language for cowards, unlike the chad java script: Javascript equality lols aside, that kind of switch(true) case anti-pattern is possible in drat near any language with a switch, and it's almost always a bad idea
|
# ? Dec 23, 2023 02:26 |
|
DaTroof posted:Javascript equality lols aside, that kind of switch(true) case anti-pattern is possible in drat near any language with a switch, and it's almost always a bad idea drat near any language? You definitely can't use the pattern in C-family languages like C, C++, Java or C#, as they all require the case expressions to be made up of only constant values. Amusingly, Java doesn't even allow something like switch (true) { case true: ... } because "boolean cannot be converted to int".
|
# ? Dec 23, 2023 12:10 |
|
LOOK I AM A TURTLE posted:drat near any language? You definitely can't use the pattern in C-family languages like C, C++, Java or C#, as they all require the case expressions to be made up of only constant values. Don’t worry, JEP 455 will fix this in a year or two!!!
|
# ? Dec 23, 2023 12:49 |
|
redleader posted:a language for cowards, unlike the chad java script: That's just a COND with unnecessary syntactical clutter.
|
# ? Dec 23, 2023 15:26 |
|
LOOK I AM A TURTLE posted:drat near any language? You definitely can't use the pattern in C-family languages like C, C++, Java or C#, as they all require the case expressions to be made up of only constant values. "drat near any" might have been an overstatement, but it can be done in, e.g., Javascript, Python, Ruby, PHP, Visual Basic, Kotlin, Swift, Erlang, and Perl. Elixir supports it with an explicit `cond` statement, which provides a little nicer syntax but is still a bit of a smell.
|
# ? Dec 23, 2023 16:05 |
|
My code smells like roses
|
# ? Dec 23, 2023 16:31 |
|
Must be nice. Mine mostly smells like tobacco and flop sweat
|
# ? Dec 23, 2023 16:39 |
|
Zopotantor posted:That's just a COND with unnecessary syntactical clutter. JavaScript is just a Scheme with unnecessary syntax clutter so this checks out!
|
# ? Dec 23, 2023 17:31 |
|
DaTroof posted:Must be nice. If your code runs and your feet smell, you might be upside-down!
|
# ? Dec 23, 2023 18:20 |
|
LOOK I AM A TURTLE posted:drat near any language? You definitely can't use the pattern in C-family languages like C, C++, Java or C#, as they all require the case expressions to be made up of only constant values. C# has gotten a little weirder. You could do the example given in C# just fine. https://dotnetfiddle.net/Y0PIxo code:
Nalin fucked around with this message at 18:39 on Dec 23, 2023 |
# ? Dec 23, 2023 18:37 |
|
pokeyman posted:JavaScript is just a Scheme with unnecessary syntax clutter so this checks out! the more features are introduced to a language the more it becomes a lisp
|
# ? Dec 23, 2023 19:42 |
|
CPColin posted:My code smells like roses My code smells awful but somehow some of the code I'm reviewing is even worse.
|
# ? Dec 23, 2023 20:00 |
|
CPColin posted:If your code runs and your feet smell, you might be upside-down! hahahahaha
|
# ? Dec 24, 2023 00:12 |
|
Nalin posted:C# has gotten a little weirder. You could do the example given in C# just fine. yeah, the pattern matching switch is a lot newer, and imo only started to become properly useful in the last couple of c# versions. it's good, but not equivalent to the switch (thing) {case "a": ... } static dispatch statement in c, java, ... i also like c#'s dedication to never naming things the same way that every other lang does. the switch expression should have been called match, Select should have been Map, etc i guess i'm just surprised by how switch works in more dynamic langs
|
# ? Dec 24, 2023 00:39 |
|
fruit company finds one weird trick to port x86 asm to ARM intel hates it! https://twitter.com/CoreSerena/status/1738623858788163962
|
# ? Dec 24, 2023 01:19 |
|
my curiosity got the better of me -- it's a specialized compressor for paged-out virtual memory that is hand-written to fit in a single 4KB page: https://opensource.apple.com/source/xnu/xnu-4570.1.46/osfmk/arm64/WKdmCompress_4k.s.auto.html Sadly, this is not the worst sin that I've seen Apple commit in their libraries. Nearly every mature iOS app has one of two things: A) A bunch of impl swizzling to work around various bugs or B) A refusal to run on anything less than the latest iOS version ullerrm fucked around with this message at 06:21 on Dec 24, 2023 |
# ? Dec 24, 2023 03:20 |
|
more falafel please posted:the more features are introduced to a language the more it becomes a lisp everything evolves toward perfection
|
# ? Dec 24, 2023 15:54 |
lisp, the crab of programming
|
|
# ? Dec 26, 2023 04:47 |
|
more falafel please posted:the more features are introduced to a language the more it becomes a lisp Polio Vax Scene posted:lisp, the crab of programming Consinization
|
# ? Dec 26, 2023 19:25 |
|
Polio Vax Scene posted:lisp, the crab of programming
|
# ? Dec 26, 2023 22:42 |
|
Dijkstracula posted:Consinization car-cons-ization was right there
|
# ? Dec 27, 2023 01:10 |
|
NihilCredo posted:car-cons-ization was right there
|
# ? Dec 27, 2023 01:26 |
|
they cdrnt think of it
|
# ? Dec 27, 2023 01:48 |
|
NihilCredo posted:car-cons-ization was right there car-cons-inogens
|
# ? Dec 27, 2023 02:39 |
|
Guess they just cdr-n't do it
|
# ? Dec 27, 2023 03:52 |
|
|
# ? Jun 1, 2024 05:00 |
|
they could have if they used a claw with current continuation
|
# ? Dec 27, 2023 04:19 |