HNHacker News
TopNewBestAskShowJobs

catpolice

666 karma · joined July 23, 2015

submissionscomments
catpolice··on It is fast or it is wrong
I'm sympathetic to some of the conclusions here but jeez, this is a really bad argument. A lot of other commenters point out ways that it's bad, and they're mostly right.

The crux of the issue is that the argument really relies on the notion of comparing two things that supposedly do "the same thing", but you really have to ignore almost everything that could ever factor into the decision between them in order to consider them the same, and what the thing is shifts from moment to moment.

The Advent of Code example is fine. Here, we have two different algorithms that perform the same computational task, and there's a performance gap because they're not the same algorithm and have have radically different time complexities.

In the Clojure vs. Clojurescript example, the author has picked a library that can run tests on the JVM or as transpiled JS code in a browser. The end result code is doing the same thing in a different sense because it implements pretty much the same algorithm (modulo technical differences in the underlying intermediate platforms). But the first performance comparison is between the Clojure and Clojurescript compile times. Trust me, there's almost no sense in which compiling the Clojure language to the bytecode it was designed to be compiled to and translating it into a different high level language in a performance-sensitive way can be considered the same task. So it's unclear why that's supposed to be meaningful. And the test-timing comparison is also a little funny, since the JS still has to be JIT compiled to machine code, which is much more complex than the equivalent bytecode compilation - there's a sense in which it's more similar to the Clojure compilation step (which takes 6.5 seconds) and it happens in less than a second.

But anyway, one can argue that all-in-all it's the same code and it's doing the same thing in the end and the one that does it in the browser is slower. But that's only the case because of that specific choice to compare library tests that can target either the JVM or the browser. That's not a choice that makes sense in general.

You don't pick between those two compilers in a vacuum - you're not going to use Clojurescript unless your code needs to run in a browser. And you _can't_ use vanilla Clojure in that case. If running in a browser is a requirement, then the compile speed and runtime performance of vanilla Clojure is meaningless because it doesn't run on the platform your program is being delivered on. The author is comparing a library that can be compiled either way and run on either platform - but the actual real world code that library is used in wouldn't have that property, and the performance comparison is pretty meaningless.

I'm going to skip the next bit because it goes further off the rails in ways that are mostly unimportant.

I think there are some less charitable ways to read the conclusion, but let's go with this: don't build applications (especially things like text editors) on the web platform, because it's super inefficient. You can make faster applications, therefore, you should.

Here's the thing: you won't, and if you do, they won't succeed. We wish our text editors weren't so resource intensive, but the responsiveness of basic text editing operations isn't what most of us look for in an editor. There are slimmer native text editors out there; their development and the development of the surrounding ecosystem moves incredibly slowly because they weren't built on a pre-existing extensible platform that thousands of developers are familiar with and so very few people want to work on them. And that makes them cumbersome for a lot of tasks, which means a lot of people won't use them.

The platform that our bloated text editors are built on is part of what they do. So a faster editor that isn't built on a familiar, extensible platform doesn't do the same thing faster - it does a subset of the things I care about, at the expense of the reasons that cause me to put up with my current editor's bloat.

You can make a faster X for any X that runs on the web platform, but to do that you're going to have to build it on less general-purpose, extensible technologies, and in many (but not all!) cases, that alone going to doom the project.

And if you want to build something that does all the things the web platform does, but more efficiently, good luck. Sure, HTML/CSS/Javascript are built on a lot of design missteps, so it's theoretically possible, but I think the ship has sailed on starting completely over.

catpolice··on Raspberry Pi Pet Detector Camera Using Python, TensorFlow, and Twilio [video]
I've noticed that a lot of cat behavior can be explained by realizing that they have an incredibly short attention span and any change in their sensory environment can distract them for the half second required to drop their entire mental state. So for the cat it's like "UGHHH I want in... Oh, there's the human! ... What's going on, why are you looking at me?"
catpolice··on 9cc: A Small C Compiler
https://eli.thegreenplace.net/2012/08/02/parsing-expressions...

Precedence climbing is also (intimately) related to Pratt parsing, and there's a useful series of articles about the two here: https://www.oilshell.org/blog/2017/03/31.html

catpolice··on Public and private class fields
Who are you talking to here?
catpolice··on Public and private class fields
See my other comment: https://news.ycombinator.com/item?id=18676680

Not breaking an API is one of the few cases where they make sense, but it's sort of a hack that you have to settle for because of back-compatibility. But even then, you've already broken the API in a lot of cases. In your example, 'area' was a field you could read and potentially set. But by changing it to a derived value, code that sets it no longer makes any sense - what do you do with width and height if somebody sets the area? The underlying model changed in a way that broke the old API either way. So yeah, just change 'area' to 'getArea()'.

catpolice··on Public and private class fields
I've been using languages with getters and setters for long enough to be familiar with them. There was a time that I thought they were useful and used them in my own code. But I've been burned enough, and thought enough about language design that I've come to avoid them. I say they're "invisible" because of the property illustrated by these two statements:

foo.bar = 0; foo.baz = 0;

One of these gets compiled/JIT-ed into a few assembly instructions and the other calls an O(n^2) function (with side effects) on a giant tree structure that foo is a part of. You can't guess which is which from looking at those, unless you've read the source for the foo class and memorized which properties are behind setters. They're "invisible" because you can't see when you're using one.

A good property for code to have is that you can infer its semantics from its syntax with as little outside information as possible. When you read a line of code, you should get reliable clues about what that makes the computer do. You might not need to know /all/ the details - e.g. a method call encapsulates the details of an operation but the name (and documentation) give you a good idea of what's happening.

The problem with getters and setters is that they do more than abstract away details, they cloak potentially important semantic information about code in ways that can be misleading.

By contrast, if I read:

foo.setBar(0); foo.baz = 0;

I might not know all the details about what setBar does, but at least I have a clue that it's more complicated than the following line.

I've been burned IRL by this kind of thing - I've seen very expensive getters mysteriously ruin hot loops (making what looked like a linear operation into an O(n^3) operation) and developers pulling their hair out because of setters that silently rejected values and all sorts associated headaches. Working in settings where they came up semi-frequently made me feel like complexity could be hidden anywhere, and reduced my confidence that I understood code that I read.

JS and other languages with reflection have a whole host of associated issues. If a field gets refactored into a getter, it's suddenly not enumerable and will silently fall out of a lot of copy operations. Suppose you want to find every place that the setter gets called, so you grep for `.bar = ` but did you remember the myriad of other ways that setter could get called (e.g. foo["bar"] =, foo[someVariable] =, Object.assign, etc.)?

In my experience, unless you have some extremely strong reason why you can't refactor or some very well-defined standards about when to use them, they're not worth the trouble they bring when code suddenly stops behaving the way you expect it to.

catpolice··on Public and private class fields
First, like the other commenters, I'm not in love with the perlish # syntax. I'm not sure why it was wise/necessary to add a previously illegal character as a prefix, rather than adding a "private" keyword, but I'm sure there's some reason.

Second, the example affords an opportunity to rant about a pet peeve of mine.

"Now ask yourself, how would you implement this class in JavaScript?"

I wouldn't. Listen folks: unless you're doing some weird/temporary debugging or you need to add some meta-functionality (e.g. logging) to an API that reeallly can't change, don't write getters/setters. If accessing or setting a property needs to do computation or have side effects, refactor so that it's done explicitly by calling a method. Anything that lets you attach invisible effects to normal syntax is an anti-pattern because it makes your code behave differently than it appears to, and therefore it's harder to reason about from the outside.

catpolice··on Model View Controller isn't
I tend to use the "model" and "view" concepts a lot when discussing architecture, but in my experience it's almost always a mistake to try and reference any specific MV* pattern for explanatory purposes - it does not have the effect of making the discussion clearer.

The issue is that there isn't actually a consensus about what constitutes the definitional features of these patterns, especially when it comes to how the concepts involved actually translate into code. For any sufficiently notable discussion of an MV* pattern, you're going to find an argument in the comments about whether the author actually understands the pattern or is talking about something else, and typically the commenters will be talking past one another.

Note that I'm NOT claiming that there's anything wrong with your favorite explanation of MV* - it may be perfectly well defined and concrete and useful once you understand it. The issue is a feature of the community: lots of other people have a different (and possibly worse) understanding of what MV* means, so when you start talking about it and your understandings don't align, confusion arises. Getting those understandings back in alignment is more trouble than the acronyms are worth.

I've seen enough conversations about concrete development issues suddenly turn into disagreements about the meaning of words to realize that nothing useful is conveyed by mentioning MV* and assuming anyone knows what you're talking about - it's better to spell out exactly what you mean in reference to the code you're actually talking about, even if you have to use more words.

catpolice··on The Case Against Quantum Computing
There's a lot of misinformation in this space, so be careful who you listen to. I hope to say as few false things as possible, but I can offer no guarantees.

One source of confusion is that there are different types of proposed quantum computers. Some, like the D-wave machines, use stochastic measurement processes to arrive at probably-correct solutions. This is called "annealing", and it's a lot like what many machine learning algorithms do to try and find global minima in error function spaces, only the quantum mechanics gives it an edge in not getting stuck in local minima for various reasons.

These aren't universal computers - they only implement very specialized algorithms in a kind of abstract sense. It's sort of like how if you take a box of different sized rocks and shake it for a while, you'll eventually find that the small rocks have made their way to the bottom and the bigger rocks have drifted to the top (this is called granular convection). There's a sense in which this is like a search algorithm that helps you find the biggest rocks. The quantum version of this (very loosely speaking) would be if the rocks sorted themselves faster because the small rocks would sometimes just tunnel through the big rocks.

Using quantum effects to speed up annealing lets you do annealing faster than a classical simulation - but most problems aren't annealing problems. So present day quantum computers are specialized machines that do a kind of computation using quantum effects, but they can't run general purpose quantum algorithms. Think of them like co-processor chips that aren't quite CPUS.

That said, it's sort of hard to define what a general purpose quantum computer would even be (for various reasons), so maybe that's unfair. Anyway, D-wave machines can't run Shor's algorithm, which is one of the examples of the "exponential speedup" over classical computation.

The (claimed) algorithmic efficiency of quantum computing as it applies to quantum algorithms has to do with how much computation is done in each step.

We represent information in physical systems and process that information by making those physical systems interact in a way that affects a state space transformation. The amount of processing we can do in "one step" depends on the size of the state space of our data representation and the kinds of operations we can affect via physical interactions. Conventional computation involves a bunch of parallel systems that have 2 distinguishable states interacting pairwise through networks of logic gates that perform a limited number of transformations.

Systems of qubits have many more than 2^N distinguishable states (technically, an infinite number), and operations on them can be arbitrary linear transformations. So each quantum logic gate can do a lot more computation than a classical binary gate. Quantum algorithms basically translate information in the limited classical state space to the bigger quantum state space, do fancy operations, then project back into the classical space. It's sort of like data parallelism in the sense that if you can do a series of small operations or one big SIMD operation, the latter will generally be faster. Operations on qubits make use of physical parallelism that's only possible in the much bigger non-classical state space.

catpolice··on The Case Against Quantum Computing
The core argument here, concerning the number of variables that need to be manipulated, isn't very clear to me - I can't tell if that's because it's an unclear argument in general, or if the author tried to simplify it for laypeople to the extent that it became unconvincingly vague for people who know a thing or two about the subject area. Given the status of the author, I'm willing to give him the benefit of the doubt (and also assume that some clarity was lost in translation).

Here's an easier-to-follow argument I've heard before (also simplified for laypeople) that might be close enough to the one the author intends to make to be useful:

Quantum algorithms are supposed to be much more efficient than conventional algorithms at certain kinds of tasks. That efficiency is calculated with the assumption that each system starts in a state where it's prepared to execute the algorithm. For conventional computers, that makes sense for a number of reasons (e.g. data/program input is linear). For quantum computers, this assumption doesn't necessarily make sense because it takes a significant amount of work (in terms of measurements, etc.) to get the system (the machinery and physical representation of the initial data) into the right quantum state. In fact, the amount of work required scales horribly with the size of the input (in terms of qubits). If you think of those state preparation steps as part of the cost of the algorithm, the quantum algorithms won't, in general, outperform the classical ones.

I've been out of the quantum computation loop for nearly a decade, so I have no idea whether that's a fair way of presenting the problem, but hopefully it helps someone understand the claims being made in the article.

catpolice··on JPEG image of Shakespeare which is also a zip file containing his complete works
Anybody have any insight into what kind of trickery goes into this? I know a decent amount about both of the compression algorithms, but I've forgotten the structure of the file formats so I can't tell if this required any really funny business.
catpolice··on Idioms of Dynamic Languages
I agree with the general point here (though I think some of the dynamic patterns, e.g. reflection and exceptions, are more often anti-patterns than they are necessary and useful).

In particular, I feel like statically typed languages force you to have a much more concrete and complete picture of the program you want to write in your head before you can make any progress writing it. In dynamic languages, I'll often start with a kind of half-formed picture and get bits and pieces working and then refactoring later isn't a big deal. But in static languages, I have to express a big chunk of the type/trait/etc. hierarchy that I'm going to be working with right off the bat, before I can write any functions that make use of those types. Then the surface area of code that needs to be refactored if my picture of the underlying type hierarchy changes seems to always be much larger. In the end, for complex programs, I tend to find the benefits of static analysis make this worth it - it's just definitely harder to get started in a static language.

Thoughts:

1. All the examples here tend to have to do with basic language features or very low-level patterns. I'd love to see some higher level examples of larger architectural patterns. As I describe above, a lot of the pain points of working with static languages come when refactoring something complex, so it'd be cool to see a kind of walkthrough of such an instance.

2. In a lot of ways, once I've finished the prototyping stage for something in a dynamic language, my code is pretty similar to how it would be if written in a static language - tend to refactor a little to tighten things up after getting the core working. I wonder how feasible it would be to create a language with a dual syntax/semantics that allowed you to prototype in a dynamic interpreted setting with fewer constraints/type annotations, then switch to a strict static mode that required you to go back and fill in everything needed to statically compile?

catpolice··on Negative Base
You don't get any information if the probability of the beam balancing is either 1 or 0. If you put everyone on the scale, the probability that it will be balanced is 0 - you don't learn anything. So the trick is to exclude some of the sample group in every measurement. You can use a binary search strategy where you divide the coins into "on the scale" and "not on the scale" groups, until you have a set of two that definitely contains the one you're searching for (and then one more measurement will tell you which one of those two it is) - but that strategy requires too many measurements, so you need to use more information at each stage, and you can't throw out coins you've determined to be non-counterfeit.
catpolice··on Negative Base
Yeah, the reason I suspect it tends to thwart programmers (if I recall correctly) is that there's a solution that looks a lot like binary search that _almost_ works, but the actual solution looks very different from it at every step. So the programmer will start with the one that looks like binary search, realize that it provides almost enough information, and try to squeeze a little more out of it by modifying it in little ways, when they sort of need to go back to the drawing board instead.
catpolice··on Negative Base
Traditionally binary search involves recursively dividing the options into two roughly equal sized groups and then using a measurement to rule out every member of one of the groups (and thus half of the search space) with every step. The solution to this problem differs from that approach in certain key ways.

It is a kind of search problem, but the steps aren't recursive and you have to use several tricks to maximize the information you get out of each measurement.

catpolice··on Negative Base
Hoo, that's one of my favorite puzzles - there was a version of it on Brooklyn Nine-Nine with no solution given, which ruined my sleep that night. I have a theory that it's actually a little harder for programmers than for other technically inclined people because the instinct to treat it as a kind of binary search problem is really hard to shake.
catpolice··on MS Windows Once Caused Second Life To Break An Inkjet Printer
Certainly the bulk of the blame falls on Second Life and the printer manufacturers for not validating inputs.

But there's another valuable lesson about interpreting binary/string blobs: don't make guesses about the format of the data from its value. You'll eventually get data that looks like one thing but isn't, and do the wrong thing with it.

I run into this all the time. Just a couple weeks ago I spent a lot of time trying to track down a bug where a programmer had decided to use a de-serialization function that would take the value of a JSON field, look for an internal object with that ID and either return the object it found or initialize a new object using the string as a value (and a random ID). So guess what happened when I tried to create a new object with a value that happened to be the same as the ID of an existing object?

The Win32 issue is just looking at the first few bytes of the input to determine its format (and how to try executing it) - it's somewhat hard to avoid here for legacy reasons, but a better design would use metadata associated with the input to determine its format rather than guessing.

catpolice··on Bye, Chrome: Why I’m switching to Firefox
Same. I actually use FF for most browsing and I haven't really noticed a huge problem with the occasional youtube video. But I watch a lot of twitch streams on the box hooked up to my TV at home and Chrome seems to be the only option for getting 60fps at the moment.
catpolice··on Good design for Humans
Yeah - I think good design should be as simple as it can while respecting the complexity of the task. Designers forget that not everyone is building search engine front pages or like, the kind of simple objects with no moving parts that tend to get touted as good design.

I'm building a development environment for professionals using a complicated DSL to interface with a powerful AI. No beginners in emergencies should ever see this thing - my users got graduate degrees to get to this point, and they're going to have to learn to use it to do their job. I'm going to make that as painless as possible, but nothing can have all the required features and make them all obvious in ten seconds.

catpolice··on Symbolics Lisp Machine Museum
My company still uses a Symbolics Lisp machine! Granted, they use it as a coffee table in the lobby.
catpolice··on The SpaceDrive Project – First Results on EMDrive and Mach-Effect Thrusters
Yeah, it's odd that they make stronger claims in the middle of the paper (e.g. "This clearly indicates that the “thrust” is not coming from the EMDrive but from some electromagnetic interaction.") than in the conclusion.
catpolice··on Parsing: a timeline
Sorry, I'm from a philosophy background so I think of anything published in the last ~100 years as "fairly recent" ;)

All I meant was that that many ideas and methods developed originally for linguistics were taken up and expanded upon in programming language research, so that they had a great deal of overlap until about half way through the timeline in the link.

catpolice··on Parsing: a timeline
Yeah, that's pretty similar to what I ended up doing - it comes pretty natural with recursive descent to just store enough of the parser state on relevant nodes that you can restart it at natural breaks.

For my application, I end up having to make expensive async queries about the expressions the user writes. In order to minimize server load/make things responsive/avoid invalidating perfectly good caches, this means that I have to know exactly what to keep and what to throw out with each edit, which means that I never want to replace any node in the AST with an identical one that was needlessly re-parsed if I can help it.

So my lexer does a lot of work trying not to throw out parts of lines that the user hasn't touched, and the parser can figure out what changes are relevant to invalidate my caches.

Oddly the restartable lexer has turned out to be the most frustrating part - selectively diffing parts of two doubly linked lists and snipping them together in the way I ended up having to is one of those things that isn't conceptually very difficult but has the potential for unusually subtle bugs.

catpolice··on Parsing: a timeline
Fast re-parsing is tricky. I'm building a JS IDE for a simple language, and it needs to only re-parse the part of the syntax tree that an edit affects (and only update the minimal number of affected DOM nodes). Writing the (recursive descent) lexer/parser by hand was easy. Being able to stream text diffs to the lexer/parser and have it rebuild only the appropriate part of the AST took... a bit of work. Writing unit tests might kill me.
catpolice··on Parsing: a timeline
This is because the two subjects were largely indistinguishable until fairly recently. Most of the theory for language parsing came from efforts to describe natural languages in terms of formal grammars, and until ALGOL, most programming languages didn't have especially complex grammars. So until recently, the study of formal languages was a linguistics thing - it's since become much more popular in the CS world.
catpolice··on Ask HN: What's an (article|book|vid) that changed the way you view programming?
I like the 100% Rich Hickey link rate in the comments so far
catpolice··on Ask HN: What's an (article|book|vid) that changed the way you view programming?
Rick Hickey's Simple Made Easy permanently made me a better programmer: https://www.infoq.com/presentations/Simple-Made-Easy

Also his talks on transducers in clojure changed the way I think about functional programming

catpolice··on A Simulated Stable Planetary System with 416 Planets in the Habitable Zone
When I read this article initially, I got the impression that here "stable" actually means that it's not sensitive to small perturbations - the orbital pattern is a local attactor and is thus sort of "self-correcting", at least over some non-trivial timespan. Someone can correct me if I'm wrong about that (in which case this whole exercise is somewhat silly).
catpolice··on How Much Does a Compiler Cost?
Sure, but the supported class of languages is very broad and certainly not limited to C/C++.
catpolice··on How Much Does a Compiler Cost?
> LLVM is smaller at 1.6 million lines, but is newer, supports only C and C++ by default

Unless I'm misunderstanding "by default", this isn't true. LLVM is language agnostic and supports many languages - even the primary C-like frontend Clang supports more than just C/C++.

← PreviousPage 2 of 5Next →