1. 6

    We need to collectively examine what the incentives are that enabled this to happen. I do not believe it was a singular failure with any particular employee. It’s easy to point to certain individuals, but they do not end up in those positions unless that behavior is fundamentally compatible with the broader corporate culture and priorities.

    Panera’s reaction here is rational given the incentive structure. Security violations in the US are currently only a PR problem, so the way to address them is through PR — tell people loudly everything is fine. Whether or not it is fine is irrelevant because the incentive structure only exists at the level of media discussion. If the story goes away, the problem goes away.

    The way to fix this is to make it illegal for a company to leak user information. Then, damage control in PR doesn’t matter because it isn’t the public the company must convince, but the courts.

    1. 3

      I’ve been working on a toy porgramming language implemention for a while, and I’ve been eagerly awaiting this section of Crafting Interpeters to be published, becuase creating my own bytecode interpreter is one o the many substeps of a PL implemention that I don’t fully grok. Thanks munificent for working on this book (and please try to get Ch 15 out quickly so I can read it too :) )

      1. 3

        Yes it’s great to see this. What other books cover bytecode interpreters?

        Most compiler textbooks don’t appear to cover the subject? As far as I remember the Dragon Book covers a “three address code”, but it’s more of an IR to compile down to assembly, not a stack machine.

        I found this article interesting – it has a very compact style:

        https://codewords.recurse.com/issues/seven/dragon-taming-with-tailbiter-a-bytecode-compiler

        1. 1

          Thank you! Hopefully the next chapters won’t take quite as long. The past couple of months had a much greater number of personal life… things… than usual.

        1. 4

          Love the book! I ported the tree-walking interpreter to Swift and wrote a little bit on how it compared to the Java version in the README.

          I’m doing the same with the bytecode/VM interpreter. Will be interesting to see how far I can get with Swift without resorting to any unsafe pointer manipulation and how the performance will compare.

          1. 1

            Awesome! I love seeing how the code maps to other languages. I think Swift is surprisingly well-suited for language stuff with it’s nice ML-like enums.

          1. 3

            This looks like a great book. Really scratches my recent itch for writing compilers! Kind of an odd question, but is there a way to pay you for your efforts? And/or get a paper edition when you’re finished?

            1. 6

              Kind of an odd question, but is there a way to pay you for your efforts?

              Strangely enough, this is one of the most common questions I get. It’s a nice feeling when the biggest concern most readers have is how to give me money. :)

              For right now, no, there isn’t. I suppose you could buy a copy of my other book (“Game Programming Patterns”) to put some cash in my pocket.

              And/or get a paper edition when you’re finished?

              Right. Once the book is done, I’ll put together a print edition. At that point, that will be the canonical way to support me. Until then, your safest bet is to join the mailing list so I can let you know when it’s available. (I only post about once a month when a new chapter is done, so don’t worry about spam overload.)

              1. 4

                For right now, no, there isn’t. I suppose you could buy a copy of my other book (“Game Programming Patterns”) to put some cash in my pocket.

                Let’s say you don’t set anything else up to make it more direct. Readers might wonder along lines, “I’d like to buy the book to get him paid but I don’t need a Game Programming Patterns book.”

                (to other readers)

                In that case, consider buying the book for his sake then donating that book to your local library to inspire future programmers. Alternatively, a gift for a programmer you know that’s shown some interest in game programming. You get to do two good things with who knows what ripple effects down the line.

                1. 2

                  Is there any particular reason you don’t add a Patreon or a similar service?

              1. 4

                In both the Python and Ruby example there were explanations about “what makes sense.” Another dimension for this could be “how are we likely to use the output?”

                The Python version (returning [””] on an empty string) has the advantage that you can always count on a string being in the output. It almost seems like a total function at two levels. It’s elegant but atypical.

                1. 2

                  Another dimension for this could be “how are we likely to use the output?”

                  The follow up to that, though, is “how likely are we to use the output correctly?

                  Functions that are really core in a system like string splitting, path manipulation, etc. are in a tricky position. They are so frequently used that you really want to make sure they do what the user intends. But, because they are so frequently used, it’s also really painful if they do something like throw an exception when the input makes the user’s intention ambiguous. So instead they get pressured into accepting more inputs than are really meaningful and then have to make somewhat arbitrary choices like this for how to interpret the weird edge cases.

                  1. 1

                    I’m interested in the question of how malleable this is. For instance, people in Python and Ruby are used to negative indexes working from the back of an array. It seems like we can make these choices and they work as long as they become commonly understood behavior.

                1. 1

                  Please consider using the release tag if you are announcing a new thing!

                  1. 4

                    Will do next time, sorry. I didn’t know that was a thing.

                  1. 8

                    Bob Nystrom writing another book is the highlight of my week. If you haven’t already read his Game Programming Patterns, definitely give it a shot; it ranks up there as one of my favorite techincal books of all time! http://gameprogrammingpatterns.com

                    1. 8

                      \o/

                    1. 8

                      I was interested in this when I first saw it, then even MORE interested when I saw it was done by Bob Nystrom, who wrote a great book on Game Programming Patterns (non-affiliate: http://a.co/aki7f6M) as well as the wren programming language (https://github.com/munificent/wren). Can’t wait to dive in to it!

                      1. 6

                        He’s also one of the Dart programming language maintainers.

                        1. 5

                          Other little know facts about yours truly:

                          • Until surprisingly recently, I had never once heard a Taylor Swift song. (Alas, I have two daughters, so it was inevitable that the streak would be broken.)

                          • I fail to finish 98.417% of projects that I start.

                          • I can juggle a pretty solid Mill’s Mess.

                          1. 2

                            I fail to finish 98.417% of projects that I start.

                            I’m still wistful about what magpie could have been ;-)

                            1. 3

                              One of the reasons I stopped working on it was that Julia came out. Julia is a hell of a lot more mature than I would have ever been able to make Magpie and it’s astonishingly similar in terms of Ruby-ish syntax + multimethods.

                            2. 2

                              I can juggle a pretty solid Mill’s Mess.

                              But can you do it while bouncing a ball on your head?

                              1. 1

                                No. :(

                        1. 18

                          I’m really excited for this. I can’t wait to read the finished version.

                          Here’s a little anecdote. A few months ago I saw a comment by Bob (the author of this book) on Reddit, saying that he’s currently working on a book about interpreters. That got me super excited, because I was working on my own book about interpreters! Slightly intimidated that someone, who’s already written a great book, will be releasing a book about the same topic and maybe competing with me, I contacted Bob. I told him about my book and asked him if we’re essentially writing the same book. I was unsure about keeping on working on my book, now that there’s a pro tackling the same issues and covering the same niche. His reply couldn’t have been more motivating and encouraging, even if he tried. He essentially told me that I should keep working on my book, that there’s always room for more books and that he can’t wait to read it. I still think back to that email from time to time and credit it with giving me one of the many pushes needed to finish the book.

                          1. 7

                            Have you thought about making print copies of your book? I’ve been looking for an excuse to play around with Go, but I heavily favor the dead tree version. Either way, congrats on finishing it!

                            1. 8

                              Yes, I plan on releasing a print version in the next couple of months. Hopefully in February. I’ll send out a message on the mailing list, as soon as I know more. The major thing that’s holding me back is creating a print-proof cover image, that has the correct size, colors, resolution, margins, etc… That’s just not my area of expertise :)

                              1. 1

                                Please do! I just bought a digital copy after forgetting for a while, but I personally would be way more excited to shell out cash for something I can hold.

                            2. 4

                              Wow! Inspiring.

                              I’m learning Go myself, and this book really excites me.

                            1. 4

                              Author here, though late to the party. I’d be happy to answer any questions you have.

                              1. 10
                                • Railway Oriented Programming really opened my eyes to a different way of error handling. It’s a great metaphor for explaining the concept.

                                • Replacing Python series by Thomas Leonard, about choosing a new language for his project 0install. Very in-depth and interesting considerations.

                                • Alternate Hard and Soft Layers was the first WikiWeb-style software pattern I was introduced to. Markedly different from the software patterns I learned in school! And yet still useful.

                                • Human Factors And Object Oriented Programming is a great example of WikiWeb culture, as programmers grapple with the OOP paradigm and how to most effectively wield it.

                                • nostrademons comment from 2008 about the lessons software engineers learn over a long career.

                                • Deep C a slideshow more than an article, but it taught me a lot about C (and how much I don’t know about it!)

                                • Magpie programming language again not truly an article, but it is a very interesting stab at proglang design. I discovered the language during my honeymoon with Ruby, and it was fascinating to see Bob’s take on a Ruby-like language with multimethods baked in. I can see why Google hired him to work on Dart.

                                1. 3

                                  I can see why Google hired him to work on Dart.

                                  For what it’s worth, I was hired before Dart existed. I got the job at Google doing JS front end programming.

                                1. 9

                                  I think the musician analogy is (mostly) a red herring. Much of the difference between an intermediate and master player is mechanical. It’s about muscles, nerves, muscle memory, hearing, maintaining the instrument, etc. There is certainly a very large mental component to it, but novel thought and creative problem solving is not a big part.

                                  If an activity that require a lot of physical and mental discipline but relatively little creativity, then I think you can learn a lot from the techniques used by musicians, athletes, and dancers.

                                  But I put programming in the same bucket as writing, architecture, and composing music. There is virtually no physical component to these tasks. The mental components require discipline, but critically, they also require coming up with novel solutions to complex problems. I don’t think there’s an equivalent to four hours in a batting cage to improve at doing that.

                                  What I do think helps are things like:

                                  • Work on your self-discipline. A big part of solving a hard problem is simply not giving up. Often, you just have to keep grinding, and anything that increases your ability to push through something when it’s frustrating is good practice. Ideas:

                                    • Long distance running or other endurance sports.
                                    • Mastering a musical instrument. It won’t make you a great problem solver, but the discpline required to practice scales for two hours will help you focus.
                                    • Reading long, complex books.
                                    • Crafts that require dedication to finish projects.
                                    • Finishing stuff in general.
                                  • Work on your self confidence. This ties in to the above point. A complex problem that doesn’t already have a ready-made solution is scary! It means no one has solved it yet, and there might not be anyone you can rely on. Maybe it’s too hard for you. When you’re hip deep in it, you need to have faith that you are smart enough to get through it. Ideas:

                                    • There’s a whole world of material around improving your confidence.
                                  • Get better at breaking problems down. The way to solve a big problem is to turn it into a bunch of little problems and solve them. This is, I think, one of the most fundamental skills of creative work. I don’t know much about how to improve it, but I definitely see that novices struggle with it.

                                  • Grow your solution toolbox. Solving a complex problem often involves combining several pieces of other solutions into a whole. The more pieces and parts you’re familiar with, the better you’re able to fit them together. Ideas:

                                    • This is another one where experience really comes into play. Every program you write is a collection of solutions you’ll be able to pull from later.
                                    • Programming challenges and contests. They are artificially small, so they don’t help with discipline, but they do give you small solutions you can combine into bigger ones.
                                    • Read other people’s code.
                                    • Programming books, especially algorithms, data structures, and other fundamentals like that.
                                  • Get better at analogies. I find problem solving very often involves translating your problem into something analogous, and then using an existing solution for that problem. This is why you so often hear stuff like, “Ah, yes, if we think of X as a graph, then we can use algorithm Y.” Sort of a lateral thinking thing.

                                    My impression is that this aspect is underappreciated by people who say they “want to be a better programmer”. They tend to want to just beeline straight to “awesome programmer” and aren’t comfortable with things that feel fuzzy or indirect. Even thinking of programming as a linear skill that you can just level up belies an overly straightline mindset.

                                    Often, the best way to get from problem to solution is not a straight line between the two. You may need to recast your problem in a different light, find a solution to that, and then remap the solution back to your original problem space.

                                    Doing this well gives you those moments of inspiration where all of a sudden a hard problem becomes trivial. But it can be frustrating since you can’t predict when those happen. Self-confidence helps. Self-discipline can hinder this. Often, for this to work, you need to stop grinding, take a step back, and let your subconscious stumble on to some association.

                                    Ideas:

                                    • Generalize yourself. Take in interests outside of your domain, and outside of programming. Spend time with people who don’t code. Stuff as much variety into your brain as you can.
                                    • Read fiction and poetry. Metaphor is a huge component of creative writing and it trains your brain to see X as if it were a Y, which is exactly the skill you’re working on. Poets are masters of this.
                                    • Watch/read comedy. A lot of humor turns on taking a scene and then realizing you were misinterpreting as X when it’s really a Y. Again, that kind of lateral perspective shift is what you’re going for.
                                    • Try writing fiction, comedy, or poetry.
                                    • Turn down the distractions. This skill tends to be a bottom-up mental process. You can’t force yourself to do it. Instead, it sort of arises spontaneously when your brain isn’t otherwise occupied. But now that we have smartphones, your brain is always occupied.

                                      Tone that down. Stare at your phone less. Spend more time walking, staring off into space, or doing physical activities that don’t require mental effort. Mow the lawn. Do some knitting. Clean the house. Whatever frees up CPU cycles for all of your background mental threads.

                                  1. 2

                                    This is excellent insight into problem solving. Thank you for writing this.

                                  1. 7

                                    Is it a problem that javascript engines are so complicated that understanding what your code actually does involves deep knowledge of the runtime?

                                    1. 9

                                      I don’t think this sort of thing is specific to JavaScript runtimes. Do you know what algorithm is used by the standard library sort function of $language?

                                      1. [Comment removed by author]

                                        1. 3

                                          Knowing the algorithm tells you the asymptotic behaviour but that can be surprisingly useless - the constant factors from e.g. cache usage patterns can easily end up being multiple orders of magnitude (and you simply can’t understand those without understanding the details of the hardware - reasoning about the abstract Haskell/Ruby machine won’t tell you anything)

                                          1. 2

                                            Have you ever switched to a custom sorting function because the one in your standard library was inappropriate?

                                            1. 6

                                              Not personally. I would imagine that database implementations (including key-value stores) are the only software that needs to do this, these days. Knuth has an entire chapter on external sorts, optimized for different situations involving data that doesn’t fit in memory, but in the modern era we no longer write one-off storage backends with that level of complexity. I guess it’s nice to remember that computing can make real advancements sometimes…

                                              1. 2

                                                If I know a sort is constrained somehow (i.e. a known interval of integers) I’ll use a radix sort or similar.

                                                1. 1

                                                  Radix sort is kinda amazing when one can get away with it. :)

                                                  1. 2

                                                    O(n) sorting is so sweet but I’ve never hit the case where my data was simultaneously that constrained and sorting it was a bottleneck.

                                                    1. 2

                                                      I’ve occasionally had that case (constrained data, sorting is a bottleneck), though not often. The last time I remember it was when I was doing some stuff with the Netflix Prize dataset, which is a giant set of movie ratings, each of them an integer 1-5. For some machine learning algorithms (e.g. decision trees), sorting the data by an axis is a bottleneck. Although even in that case, careful fiddling with data representation to be more cache-friendly made a much bigger difference to my runtime than radix sort did.

                                                  2. 1

                                                    Yes. For suffix array construction, or when I require a stable sort and the standard library uses a non-stable sort.

                                                    1. [Comment removed by author]

                                                      1. 5

                                                        The quadratic case can be easily avoided by using a non-dumb process to pick a pivot: random, median-of-three, etc.

                                                        The bigger problem with quicksort is usually that it’s not stable.

                                                        1. 1

                                                          You should probably test this before throwing out the stdlib sort, though.

                                                          These days most, if not all, standard libraries use smarter versions of quicksort to eliminate the O(n^2) case, or at least make it a lot harder to hit. A lot of them don’t even use quicksort any more, but other algorithms (like timsort) with similar performance and guaranteed worst case O(n log n) behavior.

                                                    2. 2

                                                      I know python, my go-to language, uses timsort. Timsort is complex enough that I don’t really know what is is doing under the covers at any point in time, however.

                                                  1. 2

                                                    I’m working on the code for the next book I’m planning to write, on implementing programming language interpreters. Unlike my last book, where each chapter was pretty self-contained, this one has a more coherent narrative from beginning to end. That makes it a lot harder to write it and put it online one chapter at a time. It’s possible that I’ll realize something in a later chapter that requires changes to an earlier one, and I don’t want to lead readers astray.

                                                    So my plan is to basically write the code for the two interpreters (one in Java, one in C) up front. Once that’s done, I’ll do the full outline, break it into chapters, and start writing and publishing serially. I’ve got the Java one pretty much done, and I’ve made a lot of progress on the C one. This week is getting functions and function calls implements. Hopefully closures soon.

                                                    1. 5

                                                      I’m trying to do more non-technical reading; I’ve got a collection of unread books to get through. Right now I’m on James Joyce’s “Dubliners,” which will be followed by (in no particular order):

                                                      • “Kafka on the Shore” by Haruki Murakami
                                                      • “The Brief Wondrous Life of Oscar Wao” by Junot Díaz
                                                      • “Gravity’s Rainbow” by Thomas Pynchon
                                                      • “East of Eden” by John Steinbeck
                                                      • “The Sublime Object of Ideology” by Slavoj Žižek
                                                      • “Capital” volumes 1-3 by Karl Marx (if I’m going to hold opinions about Marx and Marxism, they may as well be well-informed)
                                                      • “The Philosophy of History” by Hegel
                                                      • “Dialectic of Enlightenment” by Horkheimer & Adorno
                                                      • “Civilization and Its Discontents” by Sigmund Freud

                                                      As you can see, this is split into two categories of fiction and philosophy. If anyone has anything to add to this, let me know, although it’ll be a while before I’m done with what I’ve got.

                                                      On a technical front, I am still slowly tinkering with Ruse, my embedded Scheme for Rust (I’ve been meaning to push what I have, but life’s been getting in the way). I put up a small development blog on the Ruse website yesterday. The only post there now is a tiny one introducing the blog. I intend to use it as a space for contributors to share thoughts and think out loud about design. Ruse is a learning project, and the blog is an extension of that.

                                                      1. 3

                                                        I’m about halfway through “East of Eden” right now. I’ve been meaning to try some Steinbeck for a long time and the book came up randomly in enough discussions recently that I took the plunge. I’m really glad I did. I’m trying to read more literary fiction and “classics”, but it can be a chore sometimes. “East of Eden” manages to strike a balance of being pretty weighty while still being an enjoyable read for someone with a modern short attention span.

                                                        Obviously, his prose is magnificent. The characters leap off the page and crawl into your skull where you start to feel like they have always resided.

                                                        1. 2

                                                          Good to hear! I really enjoyed both “Of Mice and Men” and “Grapes of Wrath” when I read them. “East of Eden” may be the next book I read when I finish “Dubliners.”

                                                        2. 2

                                                          Fiction wise, I’m going through “Stand on Zanzibar” right now, it’s truly great! No idea why I left it waiting on my ereader for so long.

                                                          1. 1

                                                            I’m looking at it now, and it looks good! I don’t read much science fiction, but I may give this a try.

                                                            1. 1

                                                              This is near future fiction, there is an ai but its not that much more develloped than walter. Or so it seems at this point in the book.

                                                        1. 30

                                                          I’ve read a bunch of articles like this over the years and I never find them useful. Every paragraph boils down to something like “You shouldn’t do this thing because it’s slow. Unless the alternative is worse. Use your judgement.”

                                                          If I already have good judgement, the article doesn’t tell me anything I don’t already know. And if I don’t have good judgement, all it does is give me more ammo to defend either of my possible uninformed opinions. If I decide to use an array, Joe tells me I’m doing the right thing:

                                                          They may choose a linked list, for example, because they want zero-allocation element linking via an embedded next pointer. And yet they then end up with many lists traversals throughout the program, where a dense array representation would have been well worth the extra allocation. The naïve programmer would have happily new’d up a List<T>, and avoided some common pitfalls; yet, here the senior guy is working as hard as humanly possible to avoid a single extra allocation. They over-optimized in one dimension, and ignored many others that mattered more.

                                                          But if I decide a linked list, I’m also doing the right thing because arrays cause all of that reallocation:

                                                          The ToArray method doesn’t know the size of the output, so it must make many allocations. It’ll start with 4 elements, and then keep doubling and copying elements as necessary. And we may end up with excess storage. If we end up with 33,000 elements, for example, we will waste about 128KB of dynamic storage (32,000 X 4-byte ints).

                                                          Should I allocate something on stack? Yes!

                                                          Because they are so easy, it’s doubly important to be on the lookout for allocations in C#. Each one adds to a hard-to-quantify debt that must be repaid later on when a GC subsequently scans the heap looking for garbage.

                                                          Or wait, on the heap?

                                                          Most GC-based systems, for example, are heavily tuned to make successive small object allocations very fast.

                                                          The worst category of optimization is one that can lead to brittle and insecure code. One example of this is heavy reliance on stack allocation. In C and C++, doing stack allocation of buffers often leads to difficult choices, like fixing the buffer size and writing to it in place.

                                                          Articles like this are a good reminder that you need to write with a specific audience in mind. Duffy has a ton of expertise, but he doesn’t know which subset of it is relevant to the reader, so he shotguns it all out. But much of it cancels each other out, leaving little guidance behind.

                                                          I have definitely worked with programmers who really need to take “premature optimization is the root of all evil” to heart. The kind of person who micro-optimizes every line of code into an unreadable calcified mass of clever hacks like using xor to swap values. I know exactly what missive I would write for that person.

                                                          And I’ve worked with others, architecture astronauts who seem to think a compiler can work magic and that the best way to cure too many layers of abstraction is by hiding them behind another layer of abstraction. I know what essay I’d send to them.

                                                          But I don’t know if I could write a good article that I would send to both of them.

                                                          I do like all of the points that Duffy makes: allocation matters, readability matters, the compiler and runtime aren’t magic, think about performance, measure. I’m on board with all of that. I just worry that none of it is very actionable to someone who doesn’t already have the expertise Duffy is trying to pass along.

                                                          1. 3

                                                            But I don’t know if I could write a good article that I would send to both of them.

                                                            Perhaps you might try sending them this article?

                                                            A common difficulty in convincing people – especially about something like this, that really is a matter of taste and judgement, is that to really appreciate the argument you already need to have good taste and good judgement.

                                                            And yet there are people who clearly do not have good taste and good judgement.

                                                            One way I find success is by finding other perhaps convoluted arguments that I feel say something I already find obvious.

                                                            I am not certain whether this method is successful because by showing more people “saying the same thing” I am making the position appear more popular, or it is because the different articulations resonate somehow and find its way in.