Practical Programming: An Introduction to Computer Science Using Python

practical-programming-an-ntroduction-to-computer-science-using-python.jpg
Practical Programming – Python

Yet another book on Python programming, I read it back in 2014 and must say – I was really impressed, as it’s provided a whole set of skills that I could immediately apply. In this sense, the Pragmatic Programmers series served me well once again – this guide to Python is very practical. Seems there’s a more recent version of it so I’ll be reading it and updating this page soon!

Check Practical Programming: An Introduction to Computer Science Using Python out!

Getting started with Python

The layout of the book ensures that you are getting foundation topics first.

First, you are shown the very basics of Python: simple math and operating with variables. There is a whole chapter devoted to working with strings, their importance in any programming language is universally high.

Once you are more comfortable, you are introduced to modular approach for coding software with Python: importing functionality from standard modules and defining your own modules.

Thanks to the strict syntax requirements, writing a Python code is a thing of beauty. Functions and loops are self-explanatory in most cases, and writing code encourages you to organise logic into functions and to automatically document interfaces.

Before moving on to lists and flow controls, there’s a little bit about working with objects and methods. There’s even an introduction to testing and coding style – it’s very helpful to sort these things out while you’re still very new to Python.
Lists are an amazingly flexible feature in Python, and chapter on Lists is one of the most useful in the whole book. The true beauty of lists is that they are universal – for instance, you can open a file and then access its content as a Python list with the same common methods.

About halfway into the book, you are given enough info and shown enough examples to write quite complex yet elegant pieces of software.

More useful Python skills

Second half of the book covers more advanced topics and goes into greater level of details.

I especially appreciated the chapters on file processing (lots of good examples) and sets/dictionaries. Both chapters were very useful for the recent automation script I wrote – parsing a mix structure configuration file to produce stats based on certain fields.

The databases chapter, in my view, could have been longer and more detailed, but it still provided a very good introduction and showed all the necessary elements for you to effortlessly integrate your Python software with a database.

If you’re interested in object-oriented programming with Python, this book will give you a concise but relevant introduction. If you decide to learn how to add a graphical user interface to your Python software, there’s a chapter on that too. You are also given a great introduction to algorithms and basic approaches to searching and sorting routines.

In summary, I would say this book is an excellent way to learn basics and get started with Python. Each chapter contains lots of questions and exercises for you to answer and solve. All the concepts are provided with complete and easy to understand examples.

This book should be enough of a guidance to write your very first relatively complex software projects with Python. Will also be a great book if at any stage you feel like refreshing your Python skills.

By this book on Amazon: Practical Programming – Introduction to Python.

See Also




Book Review: Pulling Strings with Puppet

pulling-strings-with-puppet-book.jpg
Pulling Strings with Puppet

Puppet is an incredibly popular Ruby-based configuration management tool. Gaining its popularity with the open-source edition, it has become popular enough to also appear as a Puppet PE – Puppet Enterprise edition.

Update February 2019: I’m migrating book reviews from another website of mine, so this isn’t a recent review but still a great book I think you should read if you get a chance.

Pupping Strings with Puppet is now a classic: written 10 years ago, it’s still a really good introduction to configuraiton management with Puppet. James Turnbull has since written an even better book (Pro Puppet) and I’ll probably find a few even more recent introductions to Puppet, but if you have Pulling Strings with Puppet on your colleague’s desk I suggest you borrow it.

What is Puppet?

Puppet is a framework for automatic configuration management of your systems. Originally oriented an Unix systems and servers specifically, it can now be used to manage quite a range of Unix-like systems as well as Windows environments.

Both open source and enterprise (paid) edition allow you to greatly optimize and automate the process of deploying and maintaining configurations of your environments via a sciptable core that can be configured to suit all of your needs.

Puppet has 400+ configurations already tested and available online on Puppet Forge – this is basically a collection of downloadable modules for automating all sorts of systems administration tasks.

The Pulling Strings with Puppet book gives a very good introduction into common tasks of configuration management and explains the multiple layers of Puppet-based solution very well: there’s a declarative language used for defining classes and modules, then there’s a transaction layer for creating and deploying updates and, finally, there is a resource abstraction layer – this piece of magic that makes it possible to use the same configuration stanza for deploying the same change to vastly different Unix-like distros.

Deploying a Puppet infrastructure

Puppet servers are called puppet masters. These are the servers which store all configurations along with list of Puppet clients (sometimes called Puppet nodes). Clients communicate back to Puppet servers at regular intervals using RESTful API over HTTPs, checking in and downloading configurational updates if necessary.

Self-signed certificates are a requirement for all the clients and the way these are managed on the Puppet master side ensures that no unathorized access can be gained easily enough. You will find a good enough description of how this works in practice so it will be very easy to get started if you’re new to Puppet.

The book goes into lots of detail when it comes to explaining the pre-requisites (Ruby, Facter) and installation process (compiling from srouces or deploying from packages). The easiest way to deploy a Puppet client or server is probably to get Ruby installed and then deploy a Puppet Ruby gem.

I really liked the table with descriptions of all the common Puppet management commands – it’s a neat little reference giving you a good idea of what’s possible and where to look for more information once you become comfortable enough.

Using Puppet for managing configurations

It all starts with the [main] configuration namespace, and before you know it the book effortlessly takes you through configuring resources and attributes and deploying classes and modules. Puppet relies heavily on the Facter framework which is an asbtract way of documenting, configuring and presenting useful configuration elements about your environments like OS version or name of your Linux distro. The book gives a very useful description of the approach to using facts and configurative definitions.

A good few pages are used to make sure you will have the full understanding of what variables are possible in Puppet and how variable scoping is probably different from most of the scripting and programming languages you already know.

You will learn about virtual resources and how they need to be realized before the changes are actually applied, and finally will be introduced to various default types available in a Puppet installation (cron/exec/file/filebucket/group/package/yumrepo and quite a few others).

Sample Puppet configuration management environment

Perhaps the most valuable element of the whole book is a complete description of nodes, classes, users and groups needed to deploy and support a typical LAMP environment. In addition to sample configurations for managing nodes and users, you are given full code for modules managing MySQL, Apache and Postfix.

The language used for composing classes and modules in Puppet is pretty straightforward, but the complete examples will help you not only learn the syntax but also pick up some of the best practices when it comes to starting even the simplest of Linux configuration management environments.

For the most technically curious minds there are hints for deploying custom set of Facter facts and even if that doesn’t impress enough you are given instructions for creating your own type for the most flexible resource/configuration management.

Advanced Puppet usage

The last few chapters in the Pulling Strings with Puppet book show you some more advanced challenges you’ll face if you chose to explore Puppet in depth.

In addition to getting plenty of hints for performance optimisation and scaling out of your Puppet infrastructure, you will find information about migrating nodes description information into an external storage (scripts or indeed proper datastores like LDAP).

For scaling, you’ll get basic information about Mongrel (apparently it’s a Ruby friendly webserver you can use instead of Apache) but also full configuration examlpes for configuring Apache as a proxy and a load balancing solution pointing to multiple Puppet instances.

Even if you are well versed in mod_proxy or mod_ajp, reading the chapter about Puppet scalability with Mongrel and Apache proxy will be a time well spent – it doesn’t just show you what steps are needed for the desired configuration but gives you explanations of the typical challenges you’ll be trying to solve.

Summary for the Pulling Strings with Puppet book

I had thoroughly enjoyed this book the first time I had read it back in 2010 and I can still recommend it after reading it again in 2012. Majority of the topics in the book are still quite relevant and easily applicable even today, which is probably a testament to both the talents of the book author and the great planning/roadmapping of the founding geniuses behind the Puppet framework.

pulling-strings-with-puppet-book.jpg
Pulling Strings with Puppet

 




Book Review: Learning MySQL

Whether you’re completely new to MySQL databases or someone who knows it well, Learning MySQL will really help you put structure around your knowledge while teaching you a number of nice to have things about MySQL. Covering a range of topics, this book will help you understand more about MySQL installation and performance tuning, provide detailed instructions on automating simple backups and restores, all while keeping you concscious of keeping your installation or web application secure.

Installing MySQL on Linux, Windows and OSX

The book has an overwhelming amount of detail describing various ways of installing MySQL on a Unix-like system of your choice. For starters, multiple Linux distros are covered with exact commands to be used. Whether you’re a Debian fan or a RedHat like OS user – it will have detailed instructions on how to update your repos and get MySQL installed.

Windows install instructions are also provided, and even if you are a proud owner of a Mac system you’ll find commands to install MySQL quickly and easily.

There is a description of the contents of MySQL directory and even description of how file storage differs for MyISAM and InnoDB storage engines.

A description of various installation screnarios and post-install actions is very useful because it explains that installing from sources is slightly different than deploying MySQL from packages. Those of you who will use MySQL long enough to warrant an upgrade will find instructions on updating the database software to its most up-to-date version.

The same section of the book has a good reference on MySQL config file options – all the parameters are provided with a brief set of instructions on how and when they should be applied.

There is definitely enough information for you to get you started – that is, to have MySQL installed and ready to be used.

Basic and advanced querying using SQL

There is enough of  a database theory given in the book to provide a solid introuduction into basic database design principles. Good examples are provided on how NOT to create tables and storage data, explaining how each scenario can be improved with just a few tweaks. Entities and relationships are covered in good detail with complex topics like JOINs well covered with good examples.

There are many examples for data manipulation – inserting and updating date and creating/updating tables.

I really enjoyed instructions on using CSV files – for both import and export. It’s a common enough task frequently requested by users so knowing best ways to use it is certainly a worthy skill.

Finally, more advanced topics are covered in a separate chapter, this is where data aggregation, advanced joins and nested queries are explained. User variables get mentioned and basic idea behind transactions and locking is given.

User management and security in MySQL

I quited liked this section of the book, mainly because it not only explained how privileges work but also hinted at a privileges-related security improvements you can easily make. I also learned a few new commands which make life a lot easier cause you run them instead of logging into MySQL with a default client and typing SQL queries.

You will learn commands for showing privileges and explore various ways of controlling access given to a specific user. Passwords management is explained very well and shown with many examples.

An overview of the default MySQL installation completes this part of the book with a list of security aspects that you should particularly be mindful of.

MySQL backups and recovery

If you are looking for a quick guide into backing up and restoring your MySQL databases quickly, you’re covered: there’s a whole chapter in the book talking about exactly that. Apart from simple use of mysqldump and a few tips on command line parameters, this section provides a good deal of information about binary logs and commands for their management and analysis. Of course, instructions on  using binary logs for point-in-time recovery are provided.

I was impressed with the depth of this section in the book, because (similar to the installation chapter) it provided instructions for a complete solution rather just the element of initiating a backup or a restore. You’ll find instructions in scheduling your backups and restores, and scenarios explain not only typical situations but trickier ones as well – like checking/repairing corrupted tables or even restoring (actually, re-creating) corrupted GRANT tables (the privileges management ones).

There is no mention of database replication, but that’s probably to keep things simple. Those of you familiar with replication will know that although it solves quite a few requirements for backup and restore, it’s really more a high availability solution than a proper backup. If you get your dataset corrupted due to an error in your software code, replication won’t be of much use as it will simply replicate your changes to all of your MySQL servers.

Tuning MySQL for maximum performance

Another immediately applicable section of the book. Starting with a review of the configurable and tunable parameters of your MySQL options file, you will be shown techniques for analysing and improving performance of your database solution. Both instructions for improving the performance of your MySQL server and the efficiency of your SQL code are provided.

I quite liked the InnoDB section which lists main features and explains when and why you may want to use this database storage engine.

There is also a good introduction into working with slow queries, particularly the part of defining of what exactly should be treated as a slow query.

Throughout the book there are mentions of the EXPLAIN command so you will get comfortable enough with assessing the query-level performance of your database.

Using MySQL in software development

Coming from PHP background of the LAMP fame, I quite enjoyed reading simple and easy to follow instructions on getting started – it certainly added structure to my knowledge. There are mentions of both MySQL and MySQLi interfaces and even explanation of their main differences.

Perl is introduced with DBI framework in mind, and provided examples cover the complete set of database management operations, including more complex topics like answer sets.

Session management and even implementation of DB-backed user logins are explained along with lots of smaller things which you would likely find useful in your web app development.

Full source code of a web app is given at the end of the book so if your style is to skip to that part and just tinker with the code and LAMP setup until you get it working – this section is for you.

Summary for the Learning MySQL book

Learning MySQL is a great introduction for the highly popular MySQL database server. If you have some knowledge and simply want to add structure to it – you will like the book. If you are quite new to MySQL – you will like it a lot.

If you’re going to buy this book, please use this page: