Nearly four years ago, I started learning a new language, Python, because I felt that as a newer language it would make sense to use it as the implementation language for a water endpoint/meter configuration and reads store and forward system. That reason extended to someone needing to maintain the system after I was gone. Using Python alone did not make the application’s modules easier to maintain, but I give some credit to the language for it.
Of all things in Python that are visually difficult for me to comprehend are decorators. I have never used one or did not know I needed to. If I were using Python on a more regular basis, like when I was designing and implementing the system, I would just decide to conquer this subject once and for all. However, one thing I have learned over the years is to be suspicious of overly complicated things that perhaps should not be, and I leave decorators there. I could have missed it, but I was not able to find a description of decorators in Mark Pilgrim’s Dive Into Python.
Perhaps I will find that post out there that just puts it all together for me, but so far, I just see confusion where decorators are concerned.
I try never to give up, so this tutorial is a good start.
Those folks who follow this blog or http://octopusgrabbus.wordpress.com might come to the conclusion that I’ve abandoned Python, but that is not the case. I started learning Python in 2009 by writing some applets to perform database housekeeping, and then eventually implemented an application in 2010 for our water department. This application, which includes a Django-powered web site was written almost exclusively in Python.
I have been interested in functional programming for a few years now, and started looking at Haskell a couple of years ago. As the deadline to start designing our water department application loomed closer, I did not know Haskell well enough to use it. Also, as a language, Haskell did not appear to have the broad library support enjoyed by Python. So, I chose Python as the implementation language for this project.
Earlier this year I came across a description of The Joy of Clojure at my favorite book sellers — http://softpro.com — and started learning more about Clojure. Having never programmed in a functional programming language or a Lisp dialect, I am finding Clojure a little daunting. However, a project has presented itself, which involves a faster way of processing our billing data through address verification.
A project is like a carrot and stick; that is it provides cause to use extraordinary effort to learn something new quickly or solve a particularly difficult problem. The project will require more than a Clojure program. Some 4GL and bash scripts will be used. However, the Clojure program will be substantial enough to get me familiar with the language and will have required enough effort to start writing code.
One of the things that has attracted me to functional programming (FP) languages is the same thing that attracted me to object oriented languages when I first learned C++ in the 1990s. Learning C++ improved my overall programming skills, whether I was writing object-oriented software or not. With learning C++, my analogy was it was like rotating your mind 90 degrees. With Clojure it is that and more.
Just one of the ways that learning Clojure has made me think differently is using the various sequence functions. Most of what I want to do with billing data fits well into Clojure’s strengths. That is you can apply the same functions to all the data and sort out data easily that does not fit your needs. At the moment, I do not see a use for using Clojure in a multi-process/multi-threaded environment.
I am also appreciating providing for data at the beginning, binding in Clojure, declaring variables in imperative languages like C. Python’s strength in the the ability to declare an object anywhere is also in my opinion a weakness that can lead to sloppy style, and I know this from direct experience.
So my conclusion is this. If I never write another line of Clojure code after my current project, my time will not have been wasted. Clojure requires a different way of thinking. It never hurts to take a different point of view, especially with problem solving. However, I think more Clojure projects will be forthcoming.
I don’t know what it is about the Clojure community, but it is very accepting of beginners and questions that sometimes ask for feedback stating the obvious. I have been programming over thirty years and paid to do so for over twenty-five years. I have used a lot of languages, but Lisp syntax has always thrown me for a loop.
The Clojure users group on Google http://groups.google.com/group/clojure?hl=en, Getting Clojure http://www.gettingclojure.com/, and resources on this blog’s Clojure Resource Page https://drknucklehead.wordpress.com/clojure-resources/ are good places to ask questions and get help.
It would be unfair of me not to include the Python community in this tribute as well. The core Python community is always encouraging and willing to answer questions. They are also a great group of people.
These are the computer programming languages I have used over the past few years.
1985 – 1987
PL/I Subset G
1987 – 1990
C, Bliss, Assember (DEC VAX)
1990 – 2000
2000 – 2002
Java, C, C++, Perl
2004 – current
Pro Python is one of those books whose detail and clear writing took some time to appreciate. I purchased it while still learning Python, and other than taking a cursor look at the chapters, I did not have time to read it. I purchased the book during the implementation of an Automated Meter Reading (AMR) application that handles meter configuration and reads.
Eventually, I had time to read the book in greater detail. First, it contains the first, full, good description of Python decorators I have ever read. I had searched the web pretty thoroughly for an explanation before finding in Pro Python. The book breaks down advanced topics into basics, functions, classes, meta programming, and includes distribution, not always covered by other texts.
This book does more to explain the Python mindset needed for clear, concise code, than some of the explanations I have read that seem to favor dictating a “Python Way” to the reader. Therefore, once you have learned Python basics, this book is a must for your library.
Python is a great language and can solve a variety of problems. But sometimes, a plain shell script will do just fine.
#!/bin/bash # # drop_csm_users.sh -- grabs anyone running fglgo csm and kills their # process. This must run under root's user, no matter who calls it. # This has to run and allow sqlexecd to continue running. It's a little # bit different than drop_ics_users.pl # # Change History: # cat /dev/null > /tmp/csm_users ps -ef | grep -v 'grep' | grep 'fglgo csm' > /tmp/csm_processes RC1=$? if [ $RC1 -eq 0 ]; then while read line do echo -e "$line\n" ccmd=`echo $line | cut -b 8-14` kpl="kill -9 $ccmd" echo "Forking this kill command $kpl" $kpl done < /tmp/csm_processes fi