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.

                                                1. 3

                                                  Outside of work, I’m reading Sega Master System technical information, getting ready for my next emulator project. And cleaning up my NES emulator, paying various bits of tech debt that irk me.

                                                  1. 3

                                                    Working on implementing sound support in my NES emulator. I completely lack basic DSP knowledge, so this is foreign territory, but I’ve got something that sounds kinda sorta right at the moment.

                                                    Otherwise, I’m also researching other gaming consoles for potential next emulator project…

                                                    1. 3

                                                      After a lot of praise for it in tech circles on the internets, I’m reading The Soul of a New Machine.

                                                      1. 3

                                                        The praise is warranted. It’s a fantastic book.

                                                      1. 4

                                                        I finally got my NES emulator to play some games last week, so this week I’m cleaning that project up a bit (some illegal opcodes, better error reporting, docs, debugging flags, etc.) so that I can put it to the side to work on other things for a while until I’m ready to one day come back to write the APU.