Don't use dependencies, only standard libraries

Return to home
寮、 2023/02/14 — technology, programming, webdev

BITCH!! Gimme chocolate!
It’s Valentine’s Day!

As you guys already know, I hate dependencies.
I write all functionality by myself, unless I absolutely need to use a dependency (for example ncurses for desktop programs, or SDL for video games, or MySQL for web development).
But what if I told you that all these dependencies, including the absolutely necessary ones, are all written using standard libraries?
And if not, then it has a chain of dependencies, and at the very end of it it’s pure standard libraries.

Especially Javascript and Python programs are ALWAYS massive dependency hells, even if you only initialize a JS project, so you only initialize a new Vue.js, Alpine.js, or whatever other engine you’re using, it’s already pulling in hundreds of Mebibytes of unwanted cruft, only to display a blank page of nothingness, it’s absolutely absurd!
Though it’s kind of understandable, since both languages are commonly used by people who don’t know how to code, don’t know how computers work, and only want to make a quick buck, while both languages are pretty much empty (only a few basic keywords and nothing else).

But I’m seeing the same shit with PHP, which is more likely to be used by more advanced programmers/computer users, and by default provides an abundance of functionality.
PHP is so complete, in my entire 20+ years of working in it I never pulled a single external dependency ever!
The only time I did work with PHP dependencies was when I got handed a frameworked PHP project that’s full of bugs, and even then I never added any new dependencies, and if I did finger with the dependencies, I only ever reduced the amount of dependencies.
But despite that, there’s still things like Composer and Packagist, and a lot of dependencies available for download.
I just can’t get the point…

To me there’s no such a thing as “traditional development” and “modern development”.
To me there’s only the right way of programming, and the wrong way of programming.
Everything soydevs consider “modern development” is pretty much the wrong way.

EYE BREAK!!

If you have to verify by yourself, just take any random framework as-is, inspect the dependencies it comes with by default, and follow the chain all the way down until you get to a project that has no dependencies at all.
You’ll quickly see that standard libraries provide you everything you need in every single language.
In C and C++ that’s the STD libraries, in Go that’s FMT, in C# and Java that’s System, PHP doesn’t have a name for it because everything is already imported by default anyway.
C is known for not having strings, Go is known for not having arrays, Rust is known for not having nulls.
And you can still write implementations of these using their standard libraries.
For example, since PHP 8.0 there’s the str_starts_with() function.
All this is, is this (for those who use PHP 7.4 or older):

<?php
  function str_starts_with ($haystack, $needle) {
    return (string)$needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0;
  }

  $string = "Fuck you you fucking nigger";
  echo "\"$string\" starts with \"Fuck you\": ".str_starts_with($string, "Fuck you")."\n";
  echo "\"$string\" starts with \"fucking\": ".str_starts_with($string, "fucking")."\n";
?>

Let’s rewrite the same thing in C:

#include <stdio.h>
#include <string.h>

int str_starts_with (char* haystack, char *needle) {
  return needle != "" && strncmp(haystack, needle, strlen(needle)) == 0 ? 1 : 0;
}

int main () {
  char* string = "Fuck you you fucking nigger";
  printf("\"%s\" starts with \"Fuck you\": %d\n", string, str_starts_with (string, "Fuck you"));
  printf("\"%s\" starts with \"fucking\": %d\n", string, str_starts_with (string, "fucking"));

  return 0;
}

Output:

"Fuck you you fucking nigger" starts with "Fuck you": 1
"Fuck you you fucking nigger" starts with "fucking": 0

And in Go:

package main

import (
  "fmt"
  "strings"
)

func main () {
  str := "Fuck you you fucking nigger"
  fmt.Printf("\"%s\" starts with \"Fuck you\": %t\n", str, strings.HasPrefix(str, "Fuck you"))
  fmt.Printf("\"%s\" starts with \"fucking\": %t\n", str, strings.HasPrefix(str, "fucking"))
}

Output:

"Fuck you you fucking nigger" starts with "Fuck you": true
"Fuck you you fucking nigger" starts with "fucking": false