this post was submitted on 19 Jun 2025
98 points (87.1% liked)

Programmer Humor

36878 readers
106 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 1 week 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 1 week ago* (last edited 1 week 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

[–] ferric_carcinization@lemmy.ml 5 points 1 week ago (4 children)

Rust would allow you to

let ret = if some_condition {
    <a lot of expensive calculations>
    result_of_operations
} else {
    <a lot of other different expensive calculations>
    result_of_other_operations
};

Now you don't have to declare it inside the blocks.

[–] barubary@infosec.exchange 5 points 1 week ago

Similarly, Perl lets you say

my $ret = do {    if (...) {        ...    } else {        ...    }};
load more comments (3 replies)
load more comments (5 replies)
load more comments (10 replies)