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.
|Omesh Tickoo and Ravi Iyer's Making Sense of Sensors (Apress)||Apr 21, 2017|
|Low Power Wireless: 6LoWPAN, IEEE802.15.4 and the Raspberry Pi||Apr 20, 2017|
|CodeLathe's Tonido Personal Cloud||Apr 19, 2017|
|Wrapping Up the Mars Lander||Apr 18, 2017|
|MultiTaction's MT Canvus-Connect||Apr 17, 2017|
|Android Candy: Facebook Everything?!?!||Apr 14, 2017|
- Teradici's Cloud Access Platform: "Plug & Play" Cloud for the Enterprise
- Low Power Wireless: 6LoWPAN, IEEE802.15.4 and the Raspberry Pi
- The Weather Outside Is Frightful (Or Is It?)
- Simple Server Hardening
- Understanding Firewalld in Multi-Zone Configurations
- Gordon H. Williams' Making Things Smart (Maker Media, Inc.)
- Non-Linux FOSS: Control Web-Based Music!
- Server Technology's HDOT Alt-Phase Switched POPS PDU
- IGEL Universal Desktop Converter