99

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 6 months ago

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

[-] notarobot@lemm.ee 5 points 6 months ago* (last edited 6 months ago)

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 6 months ago

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 6 months 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)
this post was submitted on 19 Jun 2025
99 points (87.2% liked)

Programmer Humor

39571 readers
11 users here now

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

Rules:

founded 6 years ago
MODERATORS