Work the Shell - Coping with Aces
Good. Indeed, it's my belief that the best programmers are actually lazy and want to solve problems in the easiest and most efficient way possible. Laziness breeds ingenuity, remember, so although I could have rewritten the blackjack script to use an array of possible hand values to model the multivalue hand, why bother? The fact that a given hand has more than one value isn't really important as long as we can compensate for that fact correctly in the code.
A lot of programmers talk about highly efficient code as being “elegant”, but in my experience, most elegant code is also lazy code. I know that I'm constantly looking for those smart shortcuts, those insights that let me create something that might be less efficient in its performance, but far easier to code, far faster to debug and far speedier to deploy in the field.
One great skill that programmers can nurture is being able to recognize quickly the good enough solution too. Highly analytic by nature, we code geeks suffer from a little bit of perfectionism, and writing the perfect routine at the cost of additional days or weeks of development easily can end up being less utilitarian and less useful than having a pretty decent routine that does the job and can be improved later, in the next release, a maintenance patch or whatever.
Is this laziness what causes us to have software with so darn many bugs though? I don't think so. I think bugs in products are due to the ever-increasing level of complexity of software, be it an administrative tool for a Linux box, an Apache module or an Ajax-y Web-based utility. And software like an operating system or kernel? Of course it's going to have bugs. It's far too complex ever to test for all possible conditions, cases and situations. In fact, seeking efficient solutions that can be pushed out into the field can help reduce bugs. It's not testing software that finds the most egregious problems, but customers putting software through real-world tasks.
I'm not advocating that we should ship sloppy code, however. Simply that in the classic model of alpha and beta releases, getting code into the field ultimately can produce far more robust applications than having it stay in development forever as more and more complex test cases and usage scenarios are pushed through simulators.
But, ahem, I digress!
For now, we've come up with a nice, simple solution to the dual-value problem with Aces, and let's leave our script here for this month. Next month, we'll reintegrate the new code into the main game and add some additional code to detect when either the player or dealer has a blackjack (a two-card 21).
Dave Taylor is a 26-year veteran of UNIX, creator of The Elm Mail System, and most recently author of both the best-selling Wicked Cool Shell Scripts and Teach Yourself Unix in 24 Hours, among his 16 technical books. His main Web site is at www.intuitive.com.
Dave Taylor has been hacking shell scripts for over thirty years. Really. He's the author of the popular "Wicked Cool Shell Scripts" and can be found on Twitter as @DaveTaylor and more generally at www.DaveTaylorOnline.com.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Peppermint 7 Released
- Sony Settles in Linux Battle
- Libarchive Security Flaw Discovered
- Maru OS Brings Debian to Your Phone
- Profiles and RC Files
- Snappy Moves to New Platforms
- The Giant Zero, Part 0.x
- Git 2.9 Released
- Susan Lauber's Linux Command Line Complete Video Course (Prentice Hall)
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide