=== ANCHOR POEM ===
═════════════════════════════════════════════──────────────────────────────────────
Branches cause cache misses which are slow when done on repeat.
Better to structure your code to avoid them, if possible, for example by using
an array of function pointers instead of switch statements.
unrelated, but once the data is cached from memory, operations like bit
shifting and arithmetic are essentially free. The slowest part of the process
is moving data from RAM to cache so that the CPU can use it.
That being said, CPUs and compilers are VERY good at optimizing that type of
thing these days.
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧══════════════════════════════════════─────────────────────────────────────┘
=== SIMILARITY RANKED ===
--- #1 fediverse/3792 ---
═════════════════════════════════════════════════════════──────────────────────────
If you have a thousand options in your case / switch statement, you should
probably refactor.
consider putting function pointers (to the things you would have switched to)
in an array and instead of checking "if this enum, then this, if that enum,
then that" etc send an index into the function pointer array. That way there's
no branching at all.
The best way to generate performant code is to reduce or eliminate branches.
If you're working on a video game or networked program, this can be incredibly
important.
The second best way is probably reducing cache misses and increasing
parallelism, but those are different problems.
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧══════════════════════════════════════════════════─────────────────────────┘
--- #2 fediverse/879 ---
══════════════════════════════════════════════─────────────────────────────────────
@user-501
also it's only undefined behavior because the order of the bits aren't
defined, so if you do bitfield "pointer arithmetic" then you're screwed if you
try and be portable with it. However if you're just using bitfields as
compressed data storage then you can safely access integer.a integer.b
integer.c etc safely and easily. The compiler doesn't care what order they're
in if you don't write logic that requires them to be in a certain order
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧═══════════════════════════════════════────────────────────────────────────┘
--- #3 fediverse/1034 ---
═══════════════════════════════════════════════────────────────────────────────────
@user-192
be careful, recursion can cause stack overflows.
better to run function pointers from a loop. That way you can operate as long
as necessary. Just make sure you don't get in an infinite loop...
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧════════════════════════════════════════───────────────────────────────────┘
--- #4 fediverse/633 ---
═════════════════════════════════════════════──────────────────────────────────────
@user-192
the neat thing about BASH is that it's the glue that holds all your other code
together. Write libraries in C and call them with BASH - accomplish broader
tasks that are easier to co-create. That's why I like it - it's not the most
important, but it's quite beneficial I think _^
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧══════════════════════════════════════─────────────────────────────────────┘
--- #5 fediverse/4847 ---
════════════════════════════════════════════════════════════════───────────────────
every program should write it's RAM gamestate to disk before shutting down or
closing the program and then resume from the same spot, change my mind
(every is a strong word)
(when you re-initialize you can clean the state of leaks)
there shouldn't be leaks in the first place. if you have any leaks at all,
then you need more padding.
(... you mean boilerplate? error correction?)
... yeah that's what I meant.
(but why save the state at all?)
because then it can learn!
(... you could just write the relevant data to a config file.)
true
================= stack overflow ===============
the cool thing about being queer is you can be whatever you want and
everyone'll be cool with it
if you kinda suck then you'll figure that out when everyone cool leaves.
then the kind stay with the people who suck and then it's not cool anymore
>.>
gah this sucks. party dynamics are hard. especially when the parties are teams
of 20!!
goarsh that's quite a few
================= stack overflow ===============
wait n
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧═════════════════════════════════════════════════════════──────────────────┘
--- #6 fediverse/653 ---
═════════════════════════════════════════════──────────────────────────────────────
there's a difference between designing software and using software. Some
things can be made, and then saved for another day when their implementations
may be accomplished more ethically. It's okay to say "let's leave this as
'okay' and work on the next thing we've chosen."
Check out this piece of C code I wrote last night:
it doesn't compile, it's not finished, but I wrote it as-is
[pretend like it was called "main.c" instead of "main.txt" - had to change it
because mastodon thinks it's an invalid file]
[actually .txt didn't work, try .png]
[hmmm it realized it wasn't a valid png file, okay try screenshotting the
code, there's only 300 lines]
[sure glad there's only 300 lines]
[too bad it won't let you send .zip]
[won't let me name it main.png, presumably because they already have a
failed-verified version on their machine. will rename to main-src.png instead]
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧══════════════════════════════════════─────────────────────────────────────┘
--- #7 fediverse/4125 ---
═══════════════════════════════════════════════════════════────────────────────────
@user-883
yeah that's probably better too since it'll be easier so there'll be fewer
bugs, especially since processing audio isn't usually performance critical ^_^
TBH I just want people to make more threading primitives like locks,
semaphores, and iterators. Like... thread pools, or hashmaps that run a
function on each record stored within every time each of the threads passes a
checkpoint, or paginated arrays of data that run a function on themselves and
the records near them (with slightly different input values, of course) idk
what those are called but I can't resist putting them in everything
Anyway I do think multithreading programs that don't need it will teach you to
be a better programmer, so... depends on what you're working on I guess. Are
you preparing to be ready and working, or are you ready and working?
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧════════════════════════════════════════════════════───────────────────────┘
--- #8 fediverse/5689 ---
═══════════════════════════════════════════════════════════════════════────────────
why don't we make large arrays of vram that are slightly slower because
they're farther on the circuit-board from their host and their reception at
the processing section has to be gated such that they all enter to be
processed at once.
like that one infinite scrolling XKCD cartoon where the things move from one
screen to the other simultaneously assembly line style.
[fail safes. https://xkcd.com/2916/#xt=7&yt=35 ]
if we all feel like we're doing nothing, we'll all grow tired of it and decide
to do some prevailing. gosh I wish I wasn't so useless is code for
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧════════════════════════════════════════════════════════════════───────────┘
--- #9 fediverse/282 ---
════════════════════════════════════════════───────────────────────────────────────
@user-209
I think you're right. Every letter in the variable name is another byte the OS
has to keep track of, which was a bigger problem in the past than it is today
(when it's been made irrelevant)
it's interesting how habits persist though the conditions that caused them
have faded. like a personal reflection of the environment you learned in.
"A a = new a();" is much more concise and (crucially) you can fit more words
to the right.
"a + b = c; c -= 2; f_z.write(c); f_z.close();" could conceivably be written
on a single line if you have short variable names. and when you only have so
many lines...
glad we're not constrained by those things anymore. the skeletal code that we
look at daily is much clearer - scope is more important, and so it makes sense
to encourage a coding style that illustrates it. however I can't help but
think block formatting like this could be useful in some situations, such as
when you'd normally be compelled to write a function for an operation that
runs once or more.
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧═════════════════════════════════════──────────────────────────────────────┘
--- #10 fediverse/876 ---
══════════════════════════════════════════════─────────────────────────────────────
@user-246
there is a reason to be annoyed, and that reason is that storing numbers as
"dynamically typed" string values is both inefficient and frustrating due to
the bugs it provokes.
Not sure how common those bugs are in HTML, but dynamically typed languages
like Python and Javascript have a whole class of potential errors that are
significantly more difficult to debug than on C or Rust where the variables
are statically typed
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧═══════════════════════════════════════────────────────────────────────────┘
--- #11 fediverse/247 ---
═══════════════════════════════════════════────────────────────────────────────────
@user-195 parallel is when two programs run simultaneously, like two parallel
lines (threads) that never touch.
concurrent is when the two lines are split up into chunks and the program
switches between them - like this: -----_----
enter alternate universe
parallel is when two programs operate on the same axis - usually time - and
never interfere with each other. the OS will switch between them as
appropriate to make sure they never intersect. Sorta like this: -----_----
concurrent is when two programs are executed simultaneously, primarily
constituting computation correlated with collective contents of coordinated
collaboration between contextually related coroutines.
It's simple, even a beginner could figure it out.
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧════════════════════════════════════───────────────────────────────────────┘
--- #12 fediverse/3680 ---
════════════════════════════════════════════════════════───────────────────────────
it's probably a good idea to write pseudocode, then real code, instead of
starting with real code, and bugfixing something incomplete and more difficult
to reason with.
unless you write real code easier than pseudocode. idk do what works for you.
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧═════════════════════════════════════════════════──────────────────────────┘
--- #13 messages/129 ---
═════════════════════════════════════════════──────────────────────────────────────
So you're telling me the speed difference between Python and C is due not to
the logic that the programmer uses, but rather the optimization capabilities
of the compiler?
(An interpreter includes a compiler, it just runs it in a loop rather than a
single pass)
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧══════════════════════════════════════─────────────────────────────────────┘
--- #14 fediverse/1810 ---
═════════════════════════════════════════════════════──────────────────────────────
some people hear words like "datastructures" and "object-oriented programming"
and think they're made up terms that don't mean anything important.
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧══════════════════════════════════════════════─────────────────────────────┘
--- #15 messages/455 ---
═════════════════════════════════════════════════════──────────────────────────────
I don't understand why modern software isn't error correcting. We shouldn't
have any bugs in this day and age.
For example, if you're missing a dependency then why doesn't your program try
to, I dunno, download that dependency to the program's installation directory
and use it there? Seriously there are very few problems that are unsolvable!
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧══════════════════════════════════════════════─────────────────────────────┘
--- #16 fediverse/3800 ---
═════════════════════════════════════════════════════════──────────────────────────
@user-1352
You're absolutely right, the compiler knows better than me! Certainly the
compiler doesn't know best, but certainly the compiler knows better than me.
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧══════════════════════════════════════════════════─────────────────────────┘
--- #17 fediverse/5949 ---
══════════════════════════════════════════════════════════════════════════─────────
@user-138
I don't know what it does yet T.T
it's Lua, not C
what's the message? maybe I can help, I'm much better at bash than... actually
I'm not very good at bash, but only the cool kids are.
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧═══════════════════════════════════════════════════════════════════────────┘
--- #18 messages/412 ---
════════════════════════════════════════════════════───────────────────────────────
Coding superpower:
Start thread
While(true):
Run();
Then, whenever you want it to run something else, change the function pointer
that run() uses to call a function
At the end of the run() function, set the function pointer in the while loop
to the next one. That way you don't stack overflow from the recursion.
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧═════════════════════════════════════════════──────────────────────────────┘
--- #19 fediverse/849 ---
╔══════════════════════════════════════════════────────────────────────────────────┐
║ wish there were ascii characters that took up more than one line of code │
║ vertically. │
║ │
║ wonder if we could use a sorting algorithm, or markup language, or something │
║ like that to organize less structured data along user-customizable rules. │
║ Like, a code editor that worked with your ideas, rather than the strict │
║ expression of your text. You could pretty much write in any language, even │
║ pseudocode, and the LLM behind the scenes would translate whatever you wrote │
║ into whatever result you needed. Writing Rust, but need to fit in with C code? │
║ No worries it'll translate for you. As long as the end result is functionally │
║ the same, which could be verified by running two separate VMs that ran │
║ interpreters every time you saved. And as long as their translation layers │
║ matched completely, then odds are they're the same. And if not, well, the │
║ programmer can always debug it. It's not like this would be running on │
║ something that needed to perform in the moment? Like, improv instead of │
║ tragedies, or battles instead of strategies │
╟─────────┐ ┌───────────┤
║ similar │ chronological │ different │
╚═════════╧═══════════════════════════════════─────────────────────────┴──────────┘
--- #20 fediverse/3154 ---
═══════════════════════════════════════════════════════────────────────────────────
┌───────────────────────────┐
│ CW: re: cursing-mentioned │
└───────────────────────────┘
@user-1461
yes... I like tree shapes, you have to address them differently. Lots of
pointers, in my experience, which can be kinda fun.
I also like large heaps / soups of data that points to one-another. Structs
thrown in a pile with pointers to each other. It's great! So long as those
pointers can also point back, and you can properly trace how data flows
through the system... That's the hard part, I think.
trees though... You can start by just saving a "next / previous" with one or
both being arrays of pointers to the next or previous entries. Note: plural,
entries. That's the fun part - non-linear trees teehee
┌─────────┐ ┌───────────┐
│ similar │ chronological │ different │
╘═════════╧╧════════════════════════════════════════════════───────────────────────────┘
|