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.
|Nativ Disc||Sep 23, 2016|
|Android Browser Security--What You Haven't Been Told||Sep 22, 2016|
|The Many Paths to a Solution||Sep 21, 2016|
|Synopsys' Coverity||Sep 20, 2016|
|Naztech's Roadstar 5 Car Charger||Sep 16, 2016|
|RPi-Powered pi-topCEED Makes the Case as a Low-Cost Modular Learning Desktop||Sep 15, 2016|
- Android Browser Security--What You Haven't Been Told
- Nativ Disc
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- The Many Paths to a Solution
- Naztech's Roadstar 5 Car Charger
- Synopsys' Coverity
- Securing the Programmer
- RPi-Powered pi-topCEED Makes the Case as a Low-Cost Modular Learning Desktop
- Glass Padding
- Identity: Our Last Stand
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