Posts

Python Newbies Reject A Good Idea

Image
The YouTube Short at the bottom of this post illustrates a table-driven alternative to if-else statements in Python. I liked this tip because it was reminiscent of pointers to functions in C, which I wrote about  here . The technique allowed me to isolate code to format output to screen, printer, file, or a network socket.  Back then, it took a bit of work to convince my colleagues the value of this approach, so I was not surprised to see this Python tip dismissed in the comments section: Please don't do this in production. It's much less clear than an if/else. clarity > conciseness. Great advice, make it as hard as possible so when your company kicks you [sic] they will have no clue what this does. Different language, different time, same misunderstanding. The video described the tip in general terms, so I reimplemented it to solve a specific, more relatable, problem: #!/bin/python3 SCREEN = 1 PRINTER = 2 DISK = 3 def to_screen ():     print ( "format for screen&quo

The Intersections Of Artificial Intelligence

Image
  The car in front of me misjudged a traffic light and stopped in the crosswalk. Braking early, I left a gap should the driver wish to back up. Then I wondered, would an autonomous vehicle extend the same courtesy? But I'm getting ahead of myself. Before being courteous, autonomous driving has yet to master the rules of road. There are two prevailing approaches: solve for general AI or use geo-fencing.  The former, pursued by Tesla, is harder to achieve but will make autonomous cars capable of driving on almost any road. The latter, used by GM Cruise and Alphabet Waymo, is easier to achieve, but restricts autonomous cars to certain locations. GM Cruise is already accepting fares for its driverless taxi in San Francisco. The service, however, is bound by both time and space, allowed only to run between 10pm and 6am (lighter traffic) and within a 7x7 mile area. Choices and trade-offs such as these are common when planning and building a future. Thirty years ago, Apple introduced the

Thinking About The Apple Studio Display

Image
Steve Wozniak continues to support Apple in unexpected ways. His book, iWoz , raises my iMac 27" 5K Retina Display computer to a comfortable eye level.  Long time users of the iMac will recognize this setup, as the stand is not height adjustable. I confess I have not read Wozniak's book, and no, I did not buy the book simply to adjust the height of my display. Rather, I purchased this book for my son in 2006, who needed a subject for a grade school book report.  Wozniak's goal was to share the thrill of engineering with young minds, and he succeeded. His hardcover book serving as a monitor accessory was a bonus. When Apple recently announced the Apple Studio Display with a height adjustable stand, my Apple Watch betrayed my heart rate. It was everything I wanted for my next computer:  display separate from the CPU 27" 5K Retina Display with native 2x resolution beautiful construction a height adjustable stand At $1600 I wouldn't hesitate.  But add $400 for the he

Bookshelf: Software Engineering at Google

Image
  When I published " Beauty In The Eye Of The Coder ," my idea of beautiful code was how well it stood up to time. There I wrote: Requirements change, database fields are added, code is refactored by multiple authors. Time conspires to distort and contort programs, but the ones that endure are often considered beautiful.   The book  Software Engineering at Google  tackles the nearly incomprehensible scale of Google's software engineering efforts, and the subhead " Lessons Learned from Programming Over Time " caught my eye. Was there room for beauty in software that was engineered for scale, time, and cost? More on that later. I discovered  Software Engineering at Google  at an online  ACM TechTalk , and the book's curators, Winters and Wright, provided an excellent starting point for exploring the book's hefty 600 pages. The authors distinguished programming from software engineering, and they were careful to point out that one was not better than the ot

Integer Overflow And Underflow

Image
Q: When is optimization sub-optimal?  A: When it creates an Android bug that crashes your phone during a call to 911. Details of the bug can be found in Ars Technica , but I want to focus on the integer overflow/underflow that caused the crash: return account1.hashCode() - account2.hashCode(); Nevermind the variable names and the invocation of hashCode() . The problem is subtracting without looking, and returning a number that might be too large or too negative for the program to handle. Google corrected the code by using the Java compare() method: return Integer.compare(account1.hashCode(), account2.hashCode()); which limits the return values to -1, 0, or 1, indicating account1 is less than, equal to, or greater than account2, respectively. This raises two questions: "Why did the original code use subtraction?" and "Wasn't this tested?" Addressing the first question, I've seen overflows and underflows before, and even wrote about them in Space, Time, and I

A Different Toy Story 3, Happy New Year

Image
An electrical engineer received a custom Monopoly set from her company, STV . The bespoke tokens include a soldier, hard hat, bridge, space shuttle, rail vehicle, and school building, and you would be correct if you guessed STV was in the business of engineering, architecture, and construction management services.  The engineer writes: the picture in the center of the Monopoly board is the Coney island parachute jump. STV was involved in restoring it back in 2002.   An editor at the American Chemical Society recounted the Covid lock-down in early 2020. A travel book can be a source of strength to see the pandemic through, and ACS gave their employees a photo-rich coffee table book from National Geographic: Journeys of a Lifetime, Second Edition: 500 of the World's Greatest Trips . Now as we wrap up year two of Covid and Omicron, the book takes on a darkly humorous tone, highlighting beautiful locations we just can't get to... yet. Hoping 2022 will be a kinder new year.

A Different Toy Story, Part Deux

Image
The scientific among you might see a water molecule (H₂0), but Philip Yam, former editor of Scientific American, writes that the magazine handed out these balls to explore the science of juggling . Back in 1995, Philip also got a souvenir from the late James "The Amazing" Randi while interviewing him at a hotel over breakfast.  In Philip's words: "the magician had in particular made a name for himself by going after grifters and debunking claims of paranormal ability, especially by Uri Geller, who claimed he could bend spoons using the power of his mind. Randi pulled the same illusion on me over breakfast — in fact, he bent two spoons, breaking one. I pocketed the spoons so that our waiter wouldn’t notice them." Continuing on the theme of magic, Philip received a trick pen from Martin Gardner: " I visited Martin Gardner, the longtime Mathematical Games columnist for Scientific American, in his home in Asheville, NC, to do a profile of him in the 1990s. He