so this bro on Twitter thinks my entire life is dedicated to sitting around and waiting to teach him how to fucking code.

bro

so i decided to take this opportunity to show him not only why libraries shouldn’t log - but also why his attitude is toxic as fuck.


i am not tweeting for you

so yeah – i could spend this time talking about why it’s not my job to provide evidence of my opinions.

sure – i could rant about how i have better things to do with my time than entertain this type of targetting nonsense.

of course – i could write an entire blog about sexism and why even the thought that i somehow owe you anything or somehow have to justify my action is just out right sexist.

but im not. i assure you there are plenty of beautiful people out there who will support me here and can provide amble evidence for you.

the fact is – bro – i genuinely just don’t fucking care what you have to say or think – and 99.99% of the time i would just ignore you.

but tonight – let’s do something different

why libraries shouldn’t log

because i said so and that is enough

(it’s taking every ounce of my being to not just end the blog here…)

anyway a good library contains logic to solve a problem. period. thats fucking it.

EX: libtwitterbro

let’s take an example – imagine a library called libtwitterbro that was meant to do 1 simple thing

respond to tweets with autogenerated responses in a condescending and self-righteous way


now this would be easy enough to scaffold out - we basically just need a few things to look at our library

i’ll write this in Go as it is very similar to most of the pseudo code found in CLRS (i assume you know what that is)

just think of this as a .h file or something


// GetWomansTweet will search for a successful woman in here career and target one of her tweets
// it will return a *tweet based on the highest controversy score (C) calculated at runtime
func GetWomansTweet() *tweet, error

// SetResponseFunc will take a reference to a function func(*api, *tweet) error 
// Use this to override the default GenerateCondescending with a custom function
// of your own design.
//
// Each time a Woman's tweet is found, this will be executed and will be passed 
// an authenticated *api and the controversial *tweet in question
func SetResponseFunc(func(*api, *tweet) error 

// Run will consecutively call GetWomansTweet() and execute whatever 
// is defined for SetResponseFunc() 
func Run() error


default implementation

now that you have a clear understanding of the library we are building - lets talk about a simple program that would use this library.

// main.go
package main 

import "twitterbro"

func main() {
	
	tweet, err := twitterbro.GetWomansTweet()
	if err != nil {
        // err
    }
    // your code here to be an asshole
}
	
}

in this example maybe you don’t actually want to respond to her, perhaps you just want to write a blog and use the tweet in your blog

i hear that most people have ample free time to write such things, so this is a v important use case to consider

why this shouldn’t log

the reason that GetWomansTweet() shouldn’t log is because it shouldn’t need to - if something was important enough to go wrong with the function - it should just report that and let the implementation decide what to do

this will reduce magic, and will enforce adhering to a single principal

perhaps you as a user do not care about the error message? maybe you want to ignore it? statistically speaking men are more likely to naturally ignore women so this should be considered

furthermore, if the library did do something like log on error to standard out it is now making assumptions on behalf of the engineer which the majority of the time introduce more problems than the fickle convenience they attempt to solve

furthermore, if you look at how the linux kernel works and how primitives like STDERR and STDOUT and socket programming work making assumptions that the client using the library happens to want to do the same things you do is a bold and foolish assumption to make

the fact of the matter is that you are building tools, not making products

if a library starts to get in the business of making assumptions on behalf of the client, then it violates the basics of what a library is and tip-toes into application land

a better example

now let’s talk about passing your shit to the library, which is a slightly less terrible example than the shit above

// main.go 
package main 

import (
    "twitterbro"
    "queerlogger"
)

func main() {
	
	twitterbro.SetResponseFunc(func(*api, *tweet) error{
	    // code here to generate a nice response
	    nice := GetNiceResponse() // <-- Here we use machine learning to do something kind for someone
	    err := api.PostTweet(nice)
	    if err != nil {
	        queerlogger.Oopsie(err)
	        return err
	    }
	})
	
	queerlogger.Oopsie(twitterbro.Run()) 
}

here you can see that a really amazing engineer decided to make the world a better place and override the default condescending logic with some nice logic.

this engineer clearly understands that whoever these women are, probably are just regular people who don’t live there lives to suck the internet dick of every smelly bro that comes there way.

furthermore it looks like this engineer has chosen to use a queerlogger such as the one i wrote here.

this logger encodes STDOUT in such a way to make the logs pretty colors

if the twitterbro library logged, then our wonderful engineer here would potentially conflict with whatever choices the shitty engineer who wrote twitterbro decided to enforce at runtime

why this shouldn’t log

runtime is a sacred space, and ultimately the client calling the library is responsible for everything that happens at runtime

try telling your boss that you filled up your disks and took down production because you didn’t realize the library was writing to /var/lib

all your boss is going to hear is “you fucked up”.

so just make a good tool that returns meaningful shit, and let the client decide what to do.

the number 1 reason libraries should not log

pick literaly < < ANY > > programming language that has a standard library.

does the standard library log?

how would you feel if it did?

just stop

dude – i have no idea who you are but seriously – just stop

go home – take a bath – smoke a joint – go for a walk – make a cup of coffee

just stop – me, and the rest of the internet doesn’t owe you a damn thing - so just - fucking stop

  • nóva