this post was submitted on 19 Jun 2025
92 points (86.5% liked)

Programmer Humor

37020 readers
252 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 

Made with KolourPaint and screenshots from Kate (with the GitHub theme).

you are viewing a single comment's thread
view the rest of the comments
[–] ThirdConsul@lemmy.ml 5 points 2 weeks ago (13 children)

To be honest I always disliked variable declaration without value assignment, so to me both options suck. :)

[–] notarobot@lemm.ee 5 points 2 weeks ago* (last edited 2 weeks ago) (7 children)

What about

Let ret: Number
If (someCondition) {
    <a lot of expensive calculations>
    ret = resultOfOperations
} else {
    <a lot of other different expensive operations>
    ret = resultOfOtherOperations
}
return ret

You can't declare ret inside the brackets

[–] ThirdConsul@lemmy.ml 4 points 2 weeks ago (1 children)
let ret = someCondition ? expensiveOperation() : otherOperation() 

?

[–] notarobot@lemm.ee 2 points 2 weeks ago

Yeah. That works.

load more comments (5 replies)
load more comments (10 replies)