6 ms·
I've been writing some python the last few days. Today I did something terrible. I like to believe it was out of wisdom rather than ignorance. I needed to do so
by sgtnoodle 5y ago
I've been writing some python the last few days. Today I did something terrible. I like to believe it was out of wisdom rather than ignorance. I needed to do some nuanced bit manipulations, and so I built up a string of ascii 0's and 1's, sliced the string, and then converted back to integers.
I worked on a codebase many years ago when I was an intern. That code would read frames off a CAN bus in a car. For some reason, it could only handle about 100 frames per second before running out of CPU. It turned out someone had done the same; they turned every 8 byte CAN payload into a string of 64 characters, sliced the relevant fields out, and then converted back to integers. There were about 2000 frames per second coming in, and it was just way too inefficient.
In my usage, it will maybe never happen, outside of a unit test I wrote for it. I am really tempted to rewrite it tomorrow to use but shifts...
- taneq 5y agoReminds me of that Tao of Programming koan (if I remember it rightly) that went something like: The novice, in his frustration, struck the side of his computer. The master walked over and asked what he was doing. The novice exclaimed, "my computer is not working and I do not know why!" The master admonished him, saying "you cannot solve the problem by striking the computer without knowing what is wrong." Then the master struck the side of the computer, and it worked flawlessly. (I love this one because one time I was doing a gig and my computer refused to boot. Suspecting that the vibration from being lugged into the car and taken for a long drive had unseated something slightly, I gave it a sharp smack and power cycled it, and it started up fine.)
- bitwize 5y agoIt was one of the AI koans in Jargon: > A novice was trying to fix a broken Lisp machine by turning the power off and on. > Knight, seeing what the student was doing, spoke sternly: “You cannot fix a machine by just power-cycling it with no understanding of what is going wrong.” > Knight turned the machine off and on. > The machine worked.
- deleted 5y ago[deleted]
- taneq 5y agoYes! Ah well, I got the general gist of it right still. It's been a very long time since I read it. :)
- Sinidir 5y agoThat is hilarious.
- yifanl 5y agoA variation of the "knowing where to hit the hammer" story.
- kazinator 5y ago> I built up a string of ascii 0's and 1's, sliced the string, and then converted back to integers. How about a list of integers: $ txr This is the TXR Lisp interactive listener of TXR 274. Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet. This could be the year of the TXR desktop; I can feel it! 1> (digits 37) (3 7) 2> (digits 37 2) (1 0 0 1 0 1) 3> (reverse *2) (1 0 1 0 0 1) 4> (mapcar (op - 1) *3) (0 1 0 1 1 0) 5> (poly 2 *4) 22 :)
- TheDesolate0 5y ago
- js2 5y ago> Today I did something terrible. I like to believe it was out of wisdom rather than ignorance. I needed to do some nuanced bit manipulations, and so I built up a string of ascii 0's and 1's, sliced the string, and then converted back to integers. Similar, in awk: https://gist.github.com/jaysoffian/e41ca479d70e60efe59fded93528ab1b https://gist.github.com/jaysoffian/e41ca479d70e60efe59fded93...