6 ms·
Pretty printers are hard. "We sat down one morning," recalls Steele. "I was at the keyboard, and he was at my elbow," says Steele. "He was perfectl
by srean 8y ago
Pretty printers are hard.
"We sat down one morning," recalls Steele. "I was at
the keyboard, and he was at my elbow," says Steele.
"He was perfectly willing to let me type, but he was
also telling me what to type.
The programming session lasted 10 hours. Throughout
that entire time, Steele says, neither he nor Stallman
took a break or made any small talk. By the end of the
session, they had managed to hack the pretty print
source code to just under 100 lines. "My fingers were
on the keyboard the whole time," Steele recalls, "but
it felt like both of our ideas were flowing onto the
screen. He told me what to type, and I typed it."
The length of the session revealed itself when Steele
finally left the AI Lab. Standing outside the building
at 545 Tech Square, he was surprised to find himself
surrounded by nighttime darkness. As a programmer,
Steele was used to marathon coding sessions. Still,
something about this session was different. Working with
Stallman had forced Steele to block out all external
stimuli and focus his entire mental energies on the task
at hand. Looking back, Steele says he found the Stallman
mind-meld both exhilarating and scary at the same
time. "My first thought afterward was: it was a great
experience, very intense, and that I never wanted to do
it again in my life." - Guy Steele
Heck! to get a taste one can take a stab at writing a formatter for printing a floating point number.
- davedx 8y agoHah! Yes. I recently did a coding test for a job where one of the tasks was to write a formatter for Dutch license plates. Typically these are in the format XX-99-YY, but there are... exceptions. At first glance it seems like it won't be too hard. But it ended up sucking up something like half of the whole coding test time. I did beat it, with a lot of help from unit tests, but formatting is indeed a tougher problem than you'd expect.
- Someone 8y agohttps://en.wikipedia.org/wiki/Vehicle_registration_plates_of_the_Netherlands#Current_series https://en.wikipedia.org/wiki/Vehicle_registration_plates_of... is complex, indeed, but I don’t see how formatting would be difficult. How do they store those, other than as the formatted string? Parsing/validity checking, on the other hand, could be cumbersome.
- teraflop 8y agoI'm assuming "formatting" means "inserting hyphens in the correct place". Based on the examples in that Wikipedia page, it looks like the correct rule is to insert a hyphen between a letter and a digit that are adjacent, or in the middle of a group of 4 letters or 4 digits. But maybe there are other edge cases where that fails.
- Someone 8y agoIf you require the output to be the shortest possible (e.g. 0.1+0.11 should print as “0.21”, not as “0.21000000000000002”) and to have your output round-trip (if you read in what you printed, you get back the number you printed) I would think printing floating point numbers is harder than writing a pretty-printer. Pretty-printers have the advantage never being finished, as there always are cases where some people would say “I would format that differently”. That’s an advantage because it also means you can declare any version that works decently “finished”. For formatting floats, it’s much more black or white. Your formatter either works or it is buggy. The first working formatter for floating point numbers is from 1980, IIRC, and doing it correctly only became somewhat the expected case after Steelers 1990 paper (https://lists.nongnu.org/archive/html/gcl-devel/2012-10/pdfkieTlklRzN.pdf https://lists.nongnu.org/archive/html/gcl-devel/2012-10/pdfk...)
- jancsika 8y ago> and to have your output round-trip Unless you're simply talking about round-trip within the application itself, that's not possible.
- tlb 8y agoIt is possible, and most reasonable format systems guarantee it. Javascript guarantees that parseFloat(x.toString()) === x for any fp number x. The same extends to JSON formatting. Python guarantees that eval(str(x)) == x.
- jancsika 8y agoThat's because Javascript doesn't print out the shortest possible output. OP's requirement is that the output for 0.1 + 0.11 is displayed as 0.21, and that the output survives a round-trip. Your example satisfies the latter but not the former.
- kkylin 8y agoAnother example, more specialized than the others given, is MIT Scheme: IIRC it guarantees that when you READ back a float written by WRITE, you get the same float back, bit for bit.
- raverbashing 8y agoIt's interesting to notice after a concentrated session, how little you managed to do. Programming is fun, but sometimes it seems like you're cutting a tree down with a knife.
- Drdrdrq 8y ago...except you have this magic wand that can sometimes turn the tree into small patch of grass if you know the correct words... In my experience if it's difficult, then the approach is probably wrong.
- mayankkaizen 8y agoThat is an amazing story I have never read earlier and we are talking about Steele and Stallman. Between, I want to read more. Source of this story please?
- srean 8y agoIts from here https://www.oreilly.com/openbook/freedom/ch06.html https://www.oreilly.com/openbook/freedom/ch06.html
- Stratoscope 8y agoSpeaking of pretty printing, here is a copy of that quote made readable for mobile devices. (Don't use leading spaces to format quotes on HN, it doesn't work well.) > "We sat down one morning," recalls Steele. "I was at the keyboard, and he was at my elbow," says Steele. "He was perfectly willing to let me type, but he was also telling me what to type. > The programming session lasted 10 hours. Throughout that entire time, Steele says, neither he nor Stallman took a break or made any small talk. By the end of the session, they had managed to hack the pretty print source code to just under 100 lines. "My fingers were on the keyboard the whole time," Steele recalls, "but it felt like both of our ideas were flowing onto the screen. He told me what to type, and I typed it." > The length of the session revealed itself when Steele finally left the AI Lab. Standing outside the building at 545 Tech Square, he was surprised to find himself surrounded by nighttime darkness. As a programmer, Steele was used to marathon coding sessions. Still, something about this session was different. Working with Stallman had forced Steele to block out all external stimuli and focus his entire mental energies on the task at hand. Looking back, Steele says he found the Stallman mind-meld both exhilarating and scary at the same time. "My first thought afterward was: it was a great experience, very intense, and that I never wanted to do it again in my life." - Guy Steele
- baby 8y agoThanks! If you’re thinking about reposting broken quotes, just do it. A lot of people browse HN on mobile and will be happy to see that.
- srean 8y ago> (Don't use leading spaces to format quotes on HN, it doesn't work well.) I hear you. It does suck on small screens. But that's exactly what the leading space syntax is for -- to markup quotes. It works fine tablet/laptop/netbook etc but I hear that smaller form factors is a problem. I think the right solution is to fix the layout so that it works form mobile. Not using the markup that's specially intended for quotes seems a wrong way of going about it.
- grzm 8y ago> "But that's exactly what the leading space syntax is for -- to markup quotes" Per the HN docs, leading spaces are meant for code, not quotes. > "Text after a blank line that is indented by two or more spaces is reproduced verbatim. (This is intended for code.)" https://news.ycombinator.com/formatdoc https://news.ycombinator.com/formatdoc HN doesn't have specific formatting for quotes. Many people use leading '>' along with quotation marks and italics to set off quoted text.
- killerstorm 8y agoI can't even imagine a 10 hour coding session without breaks. The longest I did was 5 hours for ACM ICPC kind of stuff, but that left me wasted.
- tjalfi 8y agoThe code for this pretty print "@" was online[0] at one point but the site was never captured by archive.org. [0] https://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg02720.html https://people.csail.mit.edu/gregs/ll1-discuss-archive-html/...