DEV Community

Discussion on: JavaScript Conditional Branching

Collapse
 
robertseidler profile image
RobertSeidler • Edited

I really like the ternary operator in theory. Beeing able to have branching in an expression is lovely, but I hate how hard it is to read in JS (exponentially worse for nested branches).
I think python chose a way better syntax for expression branching:
Instead of:

ageGroup = (age >= 18) ? 'Adult' : "Child"
Enter fullscreen mode Exit fullscreen mode

You got:

ageGroup = 'Adult' if age >= 18 else 'Child'
Enter fullscreen mode Exit fullscreen mode
Collapse
 
peerreynders profile image
peerreynders
Collapse
 
robertseidler profile image
RobertSeidler

I do feel more and more drawn towards a more functional / declarative style of programming. It makes it (at least for me) more intuitive (both when reading and writing), than either imperative or object oriented.

Thread Thread
 
peerreynders profile image
peerreynders

I'm not sure that Python is the right "medium" for a functional/declarative style.

Collapse
 
bello profile image
Bello Osagie
a = 5
b = 10
check_condition = True if a < b else False 
print(check_condition) # True
Enter fullscreen mode Exit fullscreen mode

That may be true because some people will disagree with you. But generally, python has a better syntax. That is why Python is used for complex code structure in AI, machine Learning, data science, etc.

If you already know JavaScript on the browser or web, I recommend trying out Brython...

Collapse
 
robertseidler profile image
RobertSeidler

I'll give Brython a go, never heard of it :D

But JS has it's pros, too. In python I do miss having functions as first class objects (although that might help python, still. Making it more clear). And everything async feels slugish in python compared to js.

I enjoy switching back and forth every now and again.

Thread Thread
 
bello profile image
Bello Osagie

That's because you used Python... It happens to everyone at some point...