Monday, February 13, 2023

how i format my code

i write code. crazy right?

the thing about code is that it generally has to be human readable, and the funny thing about humans is we cannot read a program written entirely on one line very well. how easy is int main(void){printf("please kill me!\n");} to read? not very? yeah.

of course, this is a simplified example, but my point is code needs to be well formatted in order to be maintainable and not horrifying to work with. how can we do this? well, i can't give you a definitive answer, but i can ramble about how i format my code. so if you want some freshly baked Incorrect Opinions (tm), then read on!

1. indentation (or, TABS ARE EVIL!!!)

i indent my code with spaces. there are pros and cons to this, although i'm pretty sure the pros massively outweigh the cons:

pros:

  • your code will look the same across all editors
  • specific indentation (e.g. putting arguments on several lines for functions with a lot of arguments) will look the same regardless of your tab width

cons (that i could think of):

  • your source code will take up slightly more space (i'm talking additional bytes here, nothing too significant)
  • some people may prefer different tab widths and will be mildly annoyed
i feel as though i should give some examples of why tabs can cause utter chaos formatting wise. one example i can think of is something like this:
 
void docoolthings(int foo, char* bar,
                  bool baz) {
    if (baz)
        printf("%d, %s!\n", foo, bar);
}
 
this code does absolutely nothing of importance, although it serves to demonstrate one thing: tabs are not a very granular way of indenting things. with spaces, i am able to indent the second line of the arguments in our very cool function 18 spaces, which would not be possible with tabs as 18 is not divisible by 4. the closest you could get is 20, which would look like this:
 
void docoolthings(int foo, char* bar,
                    bool baz) {
 
a bit funky, don't you think? i think so at least.
 

2. pointers

i put my pointers on the left hand side. i feel this makes sense, at least to me, because i generally think of pointers as part of the type of a variable. it's not an int, it's a pointer to an int. i have nothing against people who put their pointers on the right hand side, you do you i guess, but i am very scared of people who put their pointers in the middle (like int * ohgodohfuck;). you are terrifying, please stop this heresy immediately. you keep me up at night with pure, unbridled fear. this is what i imagine a sleep paralysis demon does in it's spare time.
 

3. functions, namespaces, and the like

i put the curly braces on the same line, not the next one. i do this because it takes up less space, just looks nicer in my opinion, and anything that reminds me less of c# is probably a good thing. i don't want half the lines of code in my projects to just be curly braces. once you get to nesting for loops and if statements, you'll know what i mean.
 

4. conclusion

in conclusion. there's really not much point to this post at all. i know that's an annoying thing to be told right after reading it, but hear me out. it doesn't matter how you format your code really, as long as it's readable and not made entirely out of heinz spaghetti loops. sure, go and use tabs. you're putting your curly braces on the next line? awesome. the only exception to this is people who put their pointers in the middle. fuck you. fuck you. fuck. you. you scare me greatly.

Sunday, February 12, 2023

haiii! :3

hello! i have decided to start a blog!

why? why would anyone in their right mind start a blog over a decade after people last knew what a blog was?

well, there's two reasons:

  1. i dislike most social media
  2. i need somewhere to post about random things i like

really, i could compress that down into one reason, but "there's one reason" doesn't exactly sound as powerful, does it?

so what should you expect to see from this blog?

uuh...


uuh......

 

i do not know.

what i do know is that i'm going to be posting about a wide range of things i enjoy, be that programming, music, or various fandoms (the majority of which is very likely to be about purrfect apawcalypse because that is like half of my personality).

basically, if you can't stand my neurodivergent ass and my various hyperfixations, now would be a good time to close this tab.

hope to see you again soon! :3

how i format my code

i write code. crazy right? the thing about code is that it generally has to be human readable, and the funny thing about humans is we cannot...