Threads for ltriant

  1. 4

    This is a great article! When I wrote a NES emulator, indeed the cartridge mappers ended up being the most fascinating part of the NES.

    1. 2

      You could probably teach a whole computer engineering class on just the mappers.

    1. 30

      SQLite has so far never let me down, and enabled some things that would be otherwise in the “almost impossible” category. Still come across some amazing new feature that I had no idea about regularly (like the session extension), as well as regularly releasing big new features while remaining 100% backwards compatible always. Upgrading SQLite is a real joy: just replace sqlite3.{c,h} with the latest one, and eh yeah, that’s about it…

      fish is a pleasure to use as a daily shell - very thankful that someone has taken on the very thankless task of making a new shell and actually thinking about the ergonomics first (“Finally, a command line shell for the 90s” is the perfect slogan for this)

      1. 7

        I became a “fisher” past year and I haven’t had a reason to regret that move. Contributed some missing auto-completions to it as well.

        1. 4

          I love Fish ergonomics, but actually wish it was Bash-compatible. It’s just a bit pain when you need to integrate scripts that do not have a native Fish version, it’s slower and does often not quite work (even with Bass). Nu is another shell to look at, with even more radical choices.

          1. 3

            I installed Fish a few months ago and haven’t looked back, it is such a pleasure to use.

            1. 2

              Fish was the big thing I missed when I moved from Linux to Windows.

              1. 1

                As a daily WSL user, I’m wondering why make the move

                1. 2

                  AutoHotKey.

                  1. 1

                    i was just about to write “you should write an article about how you use autohotkey” because it seems like it would be interesting

                    then i found https://www.hillelwayne.com/post/ahk/

              2. 1

                I really like fish. Sadly I use reverse-incremental search very often in zsh and the lack of it makes fish too hard for me to use. fish has very good reverse-prefix-incremental search but since I commonly aim to resurrect commands from history from mid-line partial-match, it doesn’t work for my use-case.

                I was using fish + Starship and now I use zsh + oh-my-zsh + Starship and it’s good enough.

                1. 8

                  I use fzf to fill this hole in fish, via its ctrl-r binding

                  1. 2

                    Absolute game changer! Thank you!

                  2. 2

                    I have been using bash with the vi editing mode for years and it was only last month that I learned that you can press / in command mode to search command history. That’s completely changed how I use the shell (I can never remember the normal history search shortcut).

                    FreeBSD 14 is replacing csh with sh as the default shell and the up-arrow behaviour from csh was the big feature that everyone insisted sh needed before it could replace csh (FreeBSD’s csh up-arrow searched for things in the history matching the typed prefix). I still wouldn’t choose to use either as a daily driver, but they’re now both fine for occasional use.

                    1. 1

                      Impressed you are able to use bash vi mode. I find it rather unintuitive and prefer Emacs mode but with C-x C-e to get into nvim or when I’m in Neovim’s terminal, just going to Normal mode.

                      Strange because I have vim everywhere else. Just not here.

                      1. 2

                        I’ve written four books, a PhD thesis, a dozen papers, and at least a couple of hundred thousand lines of code in vim. At this point, convincing my fingers that any text input field is not vim is probably a lost cause. I will probably end this post by typing :wq and then have to delete it and hit post. Even if I don’t have vim mode, I hit b to go back in the command line and then have to delete the ^B.

                2. 2

                  Yep, sqlite is the first thing that came to mind when reading this thread. I’ve done a lot of data wrangling over the past year, and sqlite has come in clutch so many times.

                  It pairs well with pandas!

                1. 8

                  Implementing Wordle is the new to-do app, isn’t it?

                  1. 15

                    And, tbh, not a bad one. It’s got a lot of subtle edge cases, often pointed out in threads like this, it involves managing a slightly non-trivial amount of information, and there’s a very solid reference implementation.

                    1. 3

                      I strongly agree. Mine was a happy observation. For some reason, this was the post that made me think “oh. It’s a thing, now.”

                      1. 1

                        It feels like a time shed unnecessary cynicism, and it’s fun to see pleasant stories like Wordle’s. Happy observations a nice to collect.

                    2. 4

                      I wrote my own version of 2048 when that was super popular several years ago, and I still play it today when I want to waste some time. Sometimes those projects end up being pretty fulfilling.

                      1. 1

                        I somehow missed the whole 2048 trend. That looks fun.

                        Wordle also strikes me as a very solid choice for this kind of thing.

                    1. 2

                      I’ve been learning Nim for the past month or two, so I’d like to keep up with that next year for some other projects that I haven’t figure out yet.

                      I also want to get back into my Atari 2600 emulator, since I got stuck early this year, and decided to put it away for a while. Just getting past the horizontal sprite positioning will be enough progress for me :)

                      Outside of that, I’ve got a lot of home projects (gardening, painting, tiling, etc.) that need a lot of focus next year. And a lot of skills in those projects that need learning.

                      1. 3

                        I remember implementing the flags for this bit in the PPUMASK register in my NES emulator, but never actually integrated it into the graphics rendering.

                        I always wondered if I would ever need to come back to it…

                        1. 2

                          I had this Angelfire website during high school, in the late 90s and early 2000s.

                          It had all sorts of personal web stuff on it for a while, and then when I started doing more serious-ish web development on a different platform without ads, I put the placeholder page you see now and used it as a generic personal dropbox-like dumping site since it had FTP access.

                          1. 6

                            It’s a great book and some philosophies from the book (especially around module design) have stayed with me in the couple of years since I read it.

                            Highly recommend this one to anyone looking for books on software design. And it’s a super short read; I casually read it over a weekend.

                            1. 10

                              Woah. I had higher standards for conversations in a kindergarten. Laughable. Missing parenthesis are a problem? I can’t help but wonder what would they say if they stumbled upon other features of the language beyond missing parenthesis like traits, metaprogramming, typestate driven design, hygenic macros etc. They have no idea about the language and are completely disinterested. How one can even have a reasonable discussion after a joke of a statement like this. Regardless of what kind of problems Rust is causing or solving, this pathetic, annoying, dismissive, passive-agressive tone will make it very hard to progress. Even with much better driver/kernel module examples and APIs.

                              1. 4

                                There’s quite a bit of an impedance mismatch at the community level and it seeps through a lot in these scenarios. “Quality discourse” like this will keep happening for a while, because both communities have a lot or work to do in the “letting go of the smug dismissiveness” department. See, for example, this unofficial but pretty popular introductory document on Rust’s ownership and memory management model:

                                Mumble mumble kernel embedded something something intrusive.

                                It’s niche. You’re talking about a situation where you’re not even using your language’s runtime. Is that not a red flag that you’re doing something strange?

                                It’s also wildly unsafe.

                                But sure. Build your awesome zero-allocation lists on the stack.

                                It’s a story as old as comp.lang.lisp: people who do meaningful work in a language and are otherwise completley uninvolved in language fanboy flamewars get flak because of the more visible fan discourse, which is exactly what you expect from fan discourse.

                                1. 1

                                  Indeed. Many in the kernel community must vividly remember the history of people wanting C++ in Linux. And the swarm of Rust fanboys in 2021 must look very similar to C++ fanboys a couple of decades ago.

                                  Someone with an intimate knowledge of each of the languages can probably choose the right tool for the job. Meanwhile someone that only knows one language well will always prefer it – which is not unreasonable!

                                  My own limited experience with no_std Rust tells me it’s not nearly as easy to use as standard Rust, while my own limited experience with Linux tells me that not making mistakes in C kernel code is very difficult for mere mortals. I really hope Rust in Linux will be a great success, but only time will tell.

                                2. 3

                                  Yeah, seriously. It sounded like petulant whining. From someone who’s programmed in one language forever, and hates the idea of change.

                                1. 4

                                  It’s weird to read now, but I wrote this up a couple of years ago: https://ltriant.github.io/2019/03/23/debugging-ev-and-perls-signal-handlers.html

                                  I stopped and came back to it a couple of times over a period of a few months before finally figuring it out. I finally figured it out a few weeks before I finished up at that job, and then left Perl behind for prod systems for good.

                                  1. 3

                                    Befunge has always been my favorite esoteric language. Glad to see it was on the list!

                                    1. 2

                                      You might enjoy hexagony!

                                    1. 4

                                      This was the first IDE I used for C programming back in the early 2000s. I loved it! I didn’t realise it was still around!

                                      1. 6

                                        This makes the mistaken assumption that the reader doesn’t care what the output will look like.
                                        while cut and awk do mostly the same thing, they can behave vastly differently, see:

                                        mattrose@rome ~ % cat cutvawk
                                        foo  bar
                                        foo bar
                                        foo	bar
                                        
                                        mattrose@rome ~ % cat cutvawk | awk '{print $2}'
                                        bar
                                        bar
                                        bar
                                        
                                        mattrose@rome ~ % cat cutvawk | cut -d ' ' -f 2
                                        
                                        bar
                                        foo	bar
                                        
                                        

                                        Speed tests are fine, but they won’t tell you the right tool to use for any given job.

                                        1. 10

                                          The author specifically addresses this problem directly, clearly, and explicitly in their post. As cut doesn’t handle arbitrary spacing, they use tr to clean up the spacing first. Whether that’s squeezing spaces or converting tabs, tr can do it.

                                          This makes the mistaken assumption that the reader doesn’t care what the output will look like.

                                          This makes the mistaken assumption that the author is a complete idiot. Obviously they care about correct output.

                                          1. 7

                                            FreeBSD cut has -w to “Use whitespace (spaces and tabs) as the delimiter. Consecutive spaces and tabs count as one single field separator.”

                                            It’s had this for years, and something I miss in GNU cut; it’s pretty useful. Maybe I should look at sending a patch.

                                            1. 5

                                              Presumably the GNU project thinks sequences of whitespaces should be handled by awk, it’s referenced in the info page for cut:

                                              Note awk supports more sophisticated field processing, like reordering fields, and handling fields aligned with blank characters. By default awk uses (and discards) runs of blank characters to separate fields, and ignores leading and trailing blanks.

                                              [awk invocations snipped]

                                              This shows that the perennial discussion about “one thing well” and composability is granular and not really separable into “GNU just extends everything, *BSD keeps stuff small”, as the FreeBSD version of cut is “extended” to not need awk for successive runs of whitespace.

                                              (OpenBSD cut does not have the -w option: https://man.openbsd.org/cut)

                                              1. 5

                                                Yeah, it’s just a common use case; awk is an entire programming language and resorting to it for these kind of things is a bit overkill. Practicality beats “do one thing well” kind of purity IMO. And I also don’t think it really goes against that in the first place (it “feels” natural to me, very wishy-washy I know, but these kind of discussions tend to be).

                                            2. 1

                                              If the author cared about output, why would he cat the results to /dev/null in the OP?

                                              My point is that there are considerations other than raw speed, when deciding between cut and awk, and awk is far more forgiving of invisible whitespace difference in the input than cut is, and this is not really mentioned in the post, even though I’ve seen it happen with cut so many times.

                                              1. 3

                                                If the author cared about output, why would he cat the results to /dev/null in the OP?

                                                To better present the timing information in a blog post, and to better measure the speed of these programs without accidentally measuring the speed of their terminal emulator at consuming the output.

                                                Seriously, if the author didn’t care about output, why bother using tr in their second example at all?

                                                awk is far more forgiving of invisible whitespace difference in the input than cut is, and this is not really mentioned in the post

                                                It’s explicitly mentioned in the post. See example 2, where the author explains using tr -s for exactly this reason.

                                            3. 3

                                              You always need to know what your input looks like, right?

                                              % cat <<. | tr -s '     ' ' ' | cut -d ' ' -f 2
                                              foo  bar
                                              foo bar
                                              foo     bar
                                              .
                                              bar
                                              bar
                                              bar
                                              
                                              1. 1

                                                I had this exact case in mind reading this. It’s happened a lot and is why I’ve defaulted to always using Awk.

                                                1. 1

                                                  Yeah, they’re different tools that do different things and conflating them like this has bitten people in the backside before

                                                2. 1

                                                  The second example uses tr -s ' ' to collapse runs of spaces. If your input contains tabs as well, you could compress them too with tr -s ' \t' ' '. As I understand it,

                                                  tr -s ' \t' ' ' < inputfile | cut -d ' ' $N
                                                  

                                                  will give the same output as

                                                  awk "{print \$$N}" < inputfile
                                                  

                                                  for all positive integer values of N (up to overflow).

                                                  1. 3

                                                    that is still not the same as default awk behavior, because awk will remove leading/trailing space/tab/newlines as well

                                                    $ printf '    a  \t  b      3   '  | awk '{print $2}'
                                                    b
                                                    $ printf '    a  \t  b      3   '  | tr -s ' \t' ' ' | cut -d ' ' -f2
                                                    a
                                                    
                                                    1. 2

                                                      Ah, nice. Thanks for the correction.

                                                      The awk I have (gawk 5.1) will not remove leading or trailing newlines in the file and otherwise processes the file line-wise, but it will strip leading spaces and tabs before counting fields and cut does not.

                                                      1. 1

                                                        newlines come into picture when the input record separator doesn’t remove it

                                                        here’s an example that I answered few days back: https://stackoverflow.com/questions/64870968/sed-read-a-file-get-a-block-before-specific-line/64875721#64875721

                                                        1. 1

                                                          Sure. I was talking about the defaults, tho.

                                                1. 3

                                                  Apparently my brain decided I would be making a Gameboy emulator so that’s what I was doing until bad hours of the night last night. I can execute the boot rom, but I should make a display to see if it works correctly.

                                                  1. 2

                                                    Best of luck! Making an emulator was one of the most satisfying personal projects I’ve done.

                                                    1. 2

                                                      That’s good to hear! I’m probably the most stuck on graphics right now. Loading and rendering the tiles, etc

                                                  1. 2
                                                    • Keeping daughter entertained while my wife and I attempt to work. This is a lot harder than we expected.
                                                    • Doing garden work. Lawn needs mowing. Started a compost bin. Will plant vegetables in the coming months.
                                                    • Working on my Mega Drive emulator; still working on design for Motorola 68000 emulation. It’s more complicated than the 6502 CPU I did for my NES emulator, because at least in the 6502 an entire byte of the opcode tells you what instruction and addressing mode you’re using. I had a giant 256-length lookup table indexed by this byte. Whereas I need finer-grained inspection of bits for the 68k, e.g. the two MSB may tell you it’s a move instruction, or you may need the eight MSB to know it’s a compare instruction, or all 16 bits to know it’s a no-op. So the opcode matching is more progressive rather than a simple lookup table…
                                                    1. 3

                                                      I love going down the tilde town rabbit hole. It’s such a warm and wholesome experience.

                                                      1. 1

                                                        Adding a few last bits to my stupid simple file sharing project.

                                                        And slowly (very slowly) working on my Mega Drive emulator. I’ve got a ROM parser done. Next up is the memory map. And also reading up about the 68000.

                                                        1. 4

                                                          https://ltriant.github.io/

                                                          A while ago I decided to pack up my old blog, migrate a handful of the technical ones I liked most to a static site, and wound up with this.

                                                          Next step is move away from GitHub Pages…

                                                          1. 4

                                                            I bought myself an Arduino clone and a starter electronics kit, so I’m planning on getting into that with the goal of building my daughter fun little toys for when she’s old enough to enjoy them.

                                                            On top of that I want to educate myself more on the hardware side of computer systems.

                                                            I also want to write an emulator for a 16-bit console.

                                                            1. 5

                                                              I don’t understand the focus on “idiomatic” code. Unidiomatic code is not incorrect code.

                                                              1. 2

                                                                Unidiomatic code is likely to violate the Principle of Least Surprise. In turn, it introduces a gaping vector for bugs. Devs will assume the unidiomatic code works like the idiomatic code and has the same semantics.

                                                                That’s not to say that devs are okay to not understand the code - but when you’re moving fast and breaking things, the additional cognitive load of something that is unidiomatic is a burden.

                                                                1. 3

                                                                  Author here, I disagree. Unidiomatic code is a code smell, and needs to be corrected - especially if it has consequences on code which depends on it.

                                                                  1. 3

                                                                    I think it’s a little more complicated.

                                                                    There is Flask as an example given. Most flask projects I know are small and MVP - the kind where you quickly need a web endpoint for a library in python more than solving a problem per se. If your important library was in another language, you wouldn’t choose Flask (it’s awesome, but not the best web framework in the world without further discussion). So suddenly your perfectly well and idiomatic python code (in a small project) is not idiomatic anymore - no one cares. Why would you rewrite a perfectly fine Python 3.3 project just because everything has to be async in 3.7 (I didn’t look up the numbers, you get my point).

                                                                    And unless there’s a new swiss army knife of nice and easy web applications, people will probably continue to use Flask, and that’s a good thing.

                                                                    1. 1

                                                                      Agreed. If all new code that a team writes starts using the new idiomatic approach, the unidiomatic code is now a piece of tech debt that needs to either be paid, or will forever result in extra cognitive load, however small or large it may be.

                                                                      And it will happen again, with more and more idioms, over time. This kind of divergence takes a toll. The barrier to entry for new developers becomes a bit higher each time.

                                                                      As someone who dealt with an 18 year old codebase with a lot of this - and also as someone who contributed to that mess - it’s exhausting.

                                                                  1. 2

                                                                    Nice review. I definitely recommend the book, regardless of how much experience you have. It’s well-written and a super short read.

                                                                    My favorite chapter was “better together or better apart?”, where he discusses whether or not splitting functions and modules up into smaller units is a good idea, something he criticizes modern software development for overdoing.