Interests: programming, video games, anime, music composition

I used to be on kbin as [email protected] before it broke down.

  • 1 Post
  • 59 Comments
Joined 1 year ago
cake
Cake day: November 27th, 2023

help-circle




  • I’ve had to review resumes when we were trying to find someone else to bring on the team. My boss dumped hundreds of resumes on me and asked if any of them looked promising – that’s after going through whatever HR bullshit filters were in place – on top of all the other work I was already behind on since we didn’t have enough staff. That is the state of mind you should expect someone to be in while looking at your project.

    If anyone looks at your repo, they’re going to check briefly to see if you have any clue at all what you’re doing and whether your code likes like it’s written by the kind of person they can stand working with. Don’t make any major blunders that someone would notice with a quick glance at the repository. Be prepared to talk about your project in detail and be able to explain why you made the choices you did – you might not get asked, but if you are you should be able to justify your choices. If it gets to the point of an interview and your project looks like something that could’ve been done easily in 100 lines of Python you’d better believe I’m going to ask why the hell you wrote it in C in 2025… and I say that as someone who has written a significant amount of C professionally.

    If you say you have multiple years of professional programming experience and send me a link to a repo that has .DS_Store in it… your resume is going straight into the trash.



  • It’s really about lowering cognitive load when making edits. It’s not necessarily that someone can’t figure out how to do something more sophisticated, but that they’re more likely to get things right if the code is just kind of straightforwardly dumb.

    The last two are definitely situational – changing things like that might lower cognitive load for one kind of work but raise it significantly for another – but I can see where they’re coming from with those suggestions.




  • Same. I already have one I wrote myself that’s good enough for my needs – which means it doesn’t handle quoting or alternate line endings or other quirks. (I can just change the separator to \t if I really need commas in values, and since I control the data format, I can just say “it will always have Unix line endings” to keep it simple.)

    There’s probably thousands of open source CSV parsers out there though if you don’t want to roll your own, but I don’t have a specific recommendation.


  • Unless I really know I need something more complicated, I would just make a struct for Item. Create an array of Items that serve as the templates for instantiation. Handwrite the first pass of a few Items in C++ (or maybe C99 for syntactical convenience). Switch to CSV later and work with bulk definition in a spreadsheet.

    I wouldn’t use either a DB or JSON for this unless I had a really good reason. Like, I know I need to do a lot of complicated joins or I actually have hierarchical data – not just an array of objects, respectively. The additional complexity of dealing with them isn’t worth it otherwise.





  • Try adding some prints to stderr through my earlier test program then and see if you can find where it stops giving you output. Does output work before curl_easy_init? After it? Somewhere later on?

    Note that I did update the program to add the line with CURLOPT_ERRORBUFFER – that’s not strictly needed, but might provide more debug info if something goes wrong later in the program. (Forgot to add the setup line initially despite writing the rest of it… 🤦‍♂️️)

    You could also try adding curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); to get it to explain more details about what it’s doing internally if you can get it to print output at all.



  • As a sanity check, does this work?

    #include <curl/curl.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    size_t save_to_disk(char* ptr, size_t size, size_t nmemb, void* user_data)
    {
        /* according to curl's docs size is always 1 */
        
        FILE* fp = (FILE*)user_data;
        fprintf(stderr, "got %lu bytes\n", nmemb);
        return fwrite(ptr, size, nmemb, fp);
    }
    
    int main(int argc, char* argv[])
    {
        char errbuf[CURL_ERROR_SIZE];
        FILE* fp = NULL;
        CURLcode res;
        
        CURL* curl = curl_easy_init();
        
        if(!curl)
        {
            fprintf(stderr, "Failed to initialize curl\n");
            return EXIT_FAILURE;
        }
        
        fp = fopen("output.data", "wb");
        if(!fp)
        {
            fprintf(stderr, "Failed to open file for writing!");
            return EXIT_FAILURE;
        }
        
        curl_easy_setopt(curl, CURLOPT_URL, "https://www.wikipedia.org");
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, save_to_disk);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
        
        errbuf[0] = 0;  /* set error buffer to empty string */
        res = curl_easy_perform(curl);
        
        if(fp)
        {
            fclose(fp);
            fp = NULL;
        }
        
        if(res != CURLE_OK)
        {
            fprintf(stderr, "error code   : %d\n", res);
            fprintf(stderr, "error buffer : %s\n", errbuf);
            fprintf(stderr, "easy_strerror: %s\n", curl_easy_strerror(res));
            
            return EXIT_FAILURE;
        }
        else
        {
            fprintf(stderr, "\nDone\n");
            return EXIT_SUCCESS;
        }
    }
    

    That should write a file called output.data with the HTML from https://www.wikipedia.org and print out the number of bytes each time the write callback receives data for processing.

    On my machine, it prints the following when it works successfully (byte counts may vary for you):

    got 13716 bytes
    got 16320 bytes
    got 2732 bytes
    got 16320 bytes
    got 16320 bytes
    got 128 bytes
    got 16320 bytes
    got 16320 bytes
    got 1822 bytes
    
    Done
    

    If I change the URL to nonsense instead to make it fail, it prints text like this on my system:

    error code   : 6
    error buffer : Could not resolve host: nonsense
    easy_strerror: Couldn't resolve host name
    

    Edit: corrected missing line in source (i.e. added line with CURLOPT_ERRORBUFFER which is needed to get extra info in the error buffer on failure, of course)

    Edit 2: tweaks to wording to try to be more clear