• 0 Posts
  • 52 Comments
Joined 3 years ago
cake
Cake day: July 13th, 2023

help-circle












  • I have no love for Windows (and active hatred for Apple), and I highly value much of the features, customizability, open-source culture, and anti-capitalist aspects of Linux. But it’s not perfect.

    I’m a software engineer. I part pick and build my PCs. I’ve worked in IT. And I manage my home networking and automate my self-hosted media server. But when I tried fully switching to Linux a few years back, I held out for a few months, but it just wasn’t worth the hassle. My PC had an Nvidia graphics card, and I had no choice but to use a wifi dongle at my previous residence. Support for both was an after market hack job that needed constant maintenance. It was just annoying, my monitor’s resolution just dropping to 480p and the internet cutting out until I reapplied some patch job.

    If I had built my PC with Linux in mind, I would have done it differently. And I’m sure that I’ll try again with my next PC when I can pick compatible hardware. But my point is that I’m far from the layman and still didn’t stick with it the first time. The average computer user doesn’t need a project, doesn’t need highly customizable everything, and doesn’t care about open source. They need things to just work. And I know the problem is the lack of Linux support from major tech companies, which is BS. But that means that Linux simply can’t provide that stability and just work for a more casual user. So it is not the best option for most people.



  • But anyway, I kind of like goto too much. I find it more intuitive to just jump around and re-use parts rather than think about how to do loops without too much nesting.

    Might I introduce you to functions?

    Need to write a prompt to the console and get an input? That could be a function. Need to check if a character matches some option(s)? That’s could be a function. Need to run a specific conditional subroutine? That could be a function. And function names, done correctly, are their own documentation too.

    You main function loop could look almost like pseudo code if you do it right.

    #include <stdio.h>
    #include <stdlib.h>
    #include <stdbool.h>
    #include <string.h>
    
    char* prompt_for_input(const char* prompt_message) {
        char temp[100];
        printf(prompt_message);
        fgets(temp, 100, stdin);
        temp[strlen(temp)-1] = '\0';
        char* input = malloc(strlen(temp));
        strcpy(input,temp);
        return input;
    }
    
    int string_to_int(char* input) {
        return (int)strtol(input, NULL, 10);
    }
    
    int prompt_for_loop_count() {
        char *input = prompt_for_input("\nI'll loop over this many times: ");
        int loop_count = string_to_int(input);
        free(input);
        return loop_count;
    }
    
    bool prompt_to_do_again(){
        char *input = prompt_for_input("Let's do that again!\nShallow we? (y/n): ");
        bool do_again = (strcmp(input, "y") == 0 || strcmp(input, "Y") == 0);
        free(input);
        return do_again;
    }
    
    void print_and_decrement_counter(int loops_remaining) {
        do {
            printf("Current = %d\n", loops_remaining);
            loops_remaining--;
        } while (loops_remaining > 0);
    }
    
    int main() {
        bool need_to_get_loop_count = true;
        printf("Hello.");
        while(need_to_get_loop_count) {
            int loops_remaining = prompt_for_loop_count();
            print_and_decrement_counter(loops_remaining);
            need_to_get_loop_count = prompt_to_do_again();
        }
        printf("\nBye\n\n");
    }




  • I had a similar conversation with a friend in college who alleged that waking up after 9am meant that you are lazy. In all cases. Period.

    Stayed up until 3am partying with your friends? Better still be up by 9.

    Took the Redeye which didn’t land until 5am? Oof, enjoy your few hours remaining but don’t sleep in…

    Work a double shift through the night until 8am? Did I fucking stutter, you can only sleep until 9am, you useless fuck!

    Idk… seems silly and arbitrary.