AstonJ

AstonJ

Code you love - share yours!

Thought this would be a nice way to start the year - have you seen or written a function (or method) or piece of code that you are particularly fond of? Perhaps you admired its simplicity (or complexity!) or maybe your surprised yourself or surpassed your own expectations of what is possible?

Whatever the reason, please share! :blush:

Most Liked

ragamuf

ragamuf

Hey Ashton, when GenStage was first released I wanted to make something practical with it in Elixir and ended up writing my own job manager. Then later I found a use case for this code which was sitting on the shelf. Felt pretty sweet.

dyowee

dyowee

This sounds great. This will help a lot of junior developers like myself.

ohm

ohm

I’ve always admired the fast inverse square root function from Quake III Arena:

float q_rsqrt(float number)
{
  long i;
  float x2, y;
  const float threehalfs = 1.5F;

  x2 = number * 0.5F;
  y  = number;
  i  = * ( long * ) &y;                       // evil floating point bit level hacking
  i  = 0x5f3759df - ( i >> 1 );               // what the fuck?
  y  = * ( float * ) &i;
  y  = y * ( threehalfs - ( x2 * y * y ) );   // 1st iteration
  // y  = y * ( threehalfs - ( x2 * y * y ) );   // 2nd iteration, this can be removed

  return y;
}

This functions is called millions of times in that game, because you need to do inverse square roots to do graphics.

There’s a good write up on it’s history and meaning on Wikipedia.

Where Next?

Popular General Dev topics Top

KyleHunter
What is a good language for beginners to make apps like snapchat and instagram?
New
chasekaylee
Just like the title says :smiley: which courses you find that have had the most impact in the span of your career as a developer?
New
AstonJ
Want to plug where you work? Here’s your chance! Perhaps you could also mention what kind of stuff you’re working on? :nerd_face:
New
AstonJ
If you could work on any project, what would it be? :upside_down_face:
New
mjk
TL;DR: words that incorporate negation are acceptable, eg. independent, asymmetric, nondeterministic. An example in the book is to renam...
New
jss
What do people think about Data-Oriented Programming, like this book tackles? https://www.manning.com/books/data-oriented-programming Ho...
New
New
DevotionGeo
For me it’s six to seven steps above complete dark, on MacBook Air M1.
New
OvermindDL1
Maybe we need a thread of hosting providers we like and for what reasons. I personally like OVH, they are a very low level host (they re...
New
DevotionGeo
Hi everyone! I bought this domain name when I was planning to create a website like ElixirSchool.com, but that didn’t ever happen. Now ...
New

Other popular topics Top

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
New
AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
Rainer
My first contact with Erlang was about 2 years ago when I used RabbitMQ, which is written in Erlang, for my job. This made me curious and...
New
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1145 27688 760
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
New
New