#CursedCode

David Cantrell 🏏DrHyde@fosstodon.org
2025-06-06

There should be a #printf format `%ꙮ` that just shits an unfeasible number of zeroes all over the place.

`printf("%ꙮ\n", 32)`

000000000032.0000000000

#CursedCode #ManyEyedAbomination

James Balamutacoatless
2025-03-11

I've found the perfect way to make programmers scream in existential terror. Behold zero-indexed R!

Redefining reality with <15 lines of code is so hot right now.

Now watch as I calmly refer to v[0] while maintaining direct eye contact.

A screenshot showing the redefinition of subset operators in R to allow for 0-based indexing by globally shifting index starting locations by +1. 

Source code follows:

----

# Subset ----
# Save original subset operators
original_bracket <- `[`
original_double_bracket <- `[[`

# Create zero-based versions of subset operators
`[` <- function(x, i, ...) {
  if (is.numeric(i) && length(i) > 0 && !all(is.na(i))) {
    i <- i + 1
  }
  original_bracket(x, i, ...)
}

`[[` <- function(x, i, ...) {
  if (is.numeric(i) && !all(is.na(i))) {
    i <- i + 1
  }
  original_double_bracket(x, i, ...)
}

# Demo ----
v <- c("a", "b", "c")
v[0]
#> [1] "a"

my_name_is <- function(name) {
  paste("My name is", name[0])
}

my_name_is(c("coatless", "r", "james"))
#> [1] "coatless"
2025-03-03

So I was looking at the recently released C'n'C source code and… oh boy.

Now I understand why that game was so crashy and slow. The code is full of cargo cult programming idioms, numerically unstable in other places, often merely truncates double to int, and (my personal favorite so far) implements 3D coordinate equality comparison by testing for bitwise equality of their constituent floating point values.

#gamedev #debugging #cursedcode

2024-08-22

In today's instance of cursed JS: abusing await.

When Top-Level Await is available in ES modules, you can do this.
When the module is first evaluated, the key is evaluated. Note that this only works with keys, not with the values, even in a static block.

#javascript #cursedcode

JavaScript Code Showing:
class Foo {
    [await Promise.resolve("bar")] = 4;
}
2023-08-08

There must be something wrong with me. Even when I try to write #CursedCode, I find myself trying to make it readable.

godbolt.org/z/Ysj1171bE

Topaz, Gem Coyotetopaz@masto.brightfur.net
2023-07-04

the Swift code is every bit as cursed as the C version:

// find the default sink
// yes this is vaguely cursed, blame Frost for the initial implementation in vubar
let paInfoCmd = Process()
paInfoCmd.executableURL = URL(fileURLWithPath: "/bin/sh")
paInfoCmd.arguments = ["-c", "pactl info | grep \"Default Sink:\" | perl -pe \"s/.*?: (.*)/\\1.monitor/\" | tr -d '\n'"]
let paInfoStdout = Pipe()
paInfoCmd.standardOutput = paInfoStdout
paInfoCmd.standardError = paInfoStdout
try paInfoCmd.run()

paInfoCmd.waitUntilExit()

let output = paInfoStdout.fileHandleForReading.readDataToEndOfFile()
sink = String(data: output, encoding: .utf8)

#programming #CursedCode

Eniko (moved ➡ gamedev.place)eniko@peoplemaking.games
2022-11-24

in C we don't say "i hate you" instead we say "const" and i think that's beautiful #CursedCode

Eniko (moved ➡ gamedev.place)eniko@peoplemaking.games
2022-11-19

cleaned up the syntax for my C coroutines using computed gotos, and i think this is pretty much done. very nice :ameowhappypaws:​
#programming #CursedCode

C source code for coroutines using computed gotos

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst