97
submitted 3 weeks ago by [email protected] to c/[email protected]

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
[-] [email protected] 5 points 3 weeks ago

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

[-] [email protected] 5 points 3 weeks ago* (last edited 3 weeks 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

[-] [email protected] 5 points 3 weeks 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.

[-] [email protected] 5 points 3 weeks 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
97 points (87.0% liked)

Programmer Humor

37164 readers
487 users here now

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

Rules:

founded 5 years ago
MODERATORS