User avatar
pathetic piss kitten @kitten@elizabeth.cat
1d
my archenemy, nested ternary operators
3
1
3
0

User avatar
Eta Flag_Enby @siblingsofthevoid@void.lgbt
1d
@kitten no one should ever nest ternaries… I have always thought that to be absolutely terrible practice and it is horribly unreadable.
0
0
1
0
User avatar
Erin 💽✨ @erincandescent@erincandescent.net
1d
@kitten you would hate your average (System)Verilog file, its practically standard to write things like
assign x = condition_a ? foo :
           condition_b ? bar :
           condition_c ? baz :
           condition_d ? qux :
                         quux;
2
0
0
0
User avatar
Daphne Preston-Kendal @dpk@chaos.social
1d
@erincandescent @kitten So you know how they came out with a JS edition of SICP recently

Yeah, well, the original Scheme version has a section that depends heavily on ‘if’ and ‘cond’ being expressions and not statements. JS ‘if’ is a statement and can’t be used in a context that expects a value.

… how do you think they solved this 😬

sourceacademy.org/sicpjs/1.1.6
1
0
0
0
User avatar
pathetic piss kitten @kitten@elizabeth.cat
1d
0
0
0
0
User avatar
pathetic piss kitten @kitten@elizabeth.cat
1d
@erincandescent nooooo neocat_cry

although at least this is a serially nested ternary. the one I saw had subternaries in both branches of the main ternary
2
0
1
0
User avatar
Erin 💽✨ @erincandescent@erincandescent.net
1d
@kitten it's also pretty common to see "opencoded" conditions e.g. when you can assume due to structural factors that only one condition will ever be true:
conds_onehot: assert property ($onehot0({condition_a, condition_b, condition_c, condition_d, condition_e}));

assign x = ({8{condition_a}} & foo)
         | ({8{condition_b}} & bar)
         | ({8{condition_c}} & baz)
         | ({8{condition_d}} & qux)
         | ({8{condition_e}} & quux);



HDL is a weird world!
:neocat_think:1
1
0
0
1
User avatar
Erin 💽✨ @erincandescent@erincandescent.net
1d
@kitten ({8{foo}} is Verilog for repeat foo 8x)
1
0
0
0
User avatar
pathetic piss kitten @kitten@elizabeth.cat
1d
@erincandescent .......why do they do that?
1
0
0
0
User avatar
Erin 💽✨ @erincandescent@erincandescent.net
1d
@kitten produces smaller and hence faster synthesis outputs (assuming that the synthesis tool couldn't prove the mutual exclusiveness of the conditions in the original, which it probably can't. They can be pretty dumb)
:neocat_think:1
0
0
0
1
User avatar
fungus (penicillin producer) @hypha@cafe.mycelium.locahlo.st
1d
@kitten @erincandescent who doesn’t like some cyclomatic complexity? :D
0
0
0
0
User avatar
Persephone @mindpersephone@spookygirl.boo
1d
@kitten burn them with fire!
0
0
1
0