If you are interested in learning the R programming language, then I will share with you what I am doing to learn R. I have chosen to use Introductory Statistics with R by Peter Dalgaard.
http://www.amazon.com/Introductory-Statistics-R-Computing/dp/0387790535/
I am enjoying the book. The problems used in the book are from the life sciences. The author tells you to install the ISwR package. ISwR actually stands for "Introductory Statistics with R," so it is written for this book. The book is not perfectly clear on how to install the package, so I'll explain that.
After following the book's instructions on how to install the R programming language, you open the R programming IDE, you look for the menu item that says "Packages > Install Packages." You are asked to pick mirror site. I picked the one in Texas (TX), then you have a long list of packages to peruse. Find ISwR and select it. The only tricky part is that when it asks you if you want to install the package in a private library, you must say "yes." If you say "no" on a Windows machine, then the installation of ISwR breaks. Just say "yes."
Have fun learning R!
Robert
Sunday, October 5, 2014
Saturday, September 13, 2014
Programming Language Popularity
If you want to learn a second computer programming language, how do you choose which one to learn? One factor in making your choice might be the popularity of the language. If you want to get paid for knowing a language, you avoid languages that provide few opportunities. I think your first language should be based on a combination of popularity and its ease for learning. It is hard to beat Python as a good 1st language. You can peruse the popularity lists and see how Python stacks up in popularity.
PYPL PopularitY of Programming Language Index
From their website: "The PYPL PopularitY of Programming Language Index is created by analyzing how often language tutorials are searched on Google : the more a specific language tutorial is searched, the more popular the language is assumed to be."
https://sites.google.com/site/pydatalog/pypl/PyPL-PopularitY-of-Programming-Language
This is relying on the wisdom of the crowd.
The RedMonk Programming Language Rankings
The "RedMonk Programming Language Rankings" are derived from a correlation of programming activity on GitHub (usage) and Stack Overflow (discussion). This is a measure of language usage.
Go to this website and look for the latest ranking:
http://redmonk.com/sogrady/category/programming-languages/
Besides rankings, there are articles. An article at the time of writing this post is "Will Python Kill R?" (R being a statistical analysis language)
http://redmonk.com/sogrady/2013/11/26/python-r/
The TIOBE Index
The monthly TIOBE Programming Community Index shows the top 10 languages' popularity graphically and the top 20 languages with a rating. The numbers are based on searching the Web with certain phrases that include language names and counting the numbers of hits returned. This is a measure of interest in a language.
http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
The Transparent Language Popularity Index
This ranking is also based on internet searches. This website makes the open source software used for the ranking available for you to download, study, and use it yourself if you wish.
http://lang-index.sourceforge.net/
Trendy Skills
This website measures Skills that employers seek in the IT industry. This is the only list based on employment
http://trendyskills.com/
This webpage is interactive. You can click on the bottom to view by absolute popularity, popularity by percentage, and salary. The salary numbers might be misleading. If a preponderance of jobs for a language are in California, then that salary will be available only in California.
Trendy listed a language I needed to look up: "S". S is a statistical programming language.
http://en.wikipedia.org/wiki/S_%28programming_language%29
I am familiar with a major variant of S, called "R," but S was news to me.
No matter how many languages you know, you are always wondering what you should learn next. These popularity lists might be helpful to you.
Robert
PYPL PopularitY of Programming Language Index
From their website: "The PYPL PopularitY of Programming Language Index is created by analyzing how often language tutorials are searched on Google : the more a specific language tutorial is searched, the more popular the language is assumed to be."
https://sites.google.com/site/pydatalog/pypl/PyPL-PopularitY-of-Programming-Language
This is relying on the wisdom of the crowd.
The RedMonk Programming Language Rankings
The "RedMonk Programming Language Rankings" are derived from a correlation of programming activity on GitHub (usage) and Stack Overflow (discussion). This is a measure of language usage.
Go to this website and look for the latest ranking:
http://redmonk.com/sogrady/category/programming-languages/
Besides rankings, there are articles. An article at the time of writing this post is "Will Python Kill R?" (R being a statistical analysis language)
http://redmonk.com/sogrady/2013/11/26/python-r/
The TIOBE Index
The monthly TIOBE Programming Community Index shows the top 10 languages' popularity graphically and the top 20 languages with a rating. The numbers are based on searching the Web with certain phrases that include language names and counting the numbers of hits returned. This is a measure of interest in a language.
http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
The Transparent Language Popularity Index
This ranking is also based on internet searches. This website makes the open source software used for the ranking available for you to download, study, and use it yourself if you wish.
http://lang-index.sourceforge.net/
Trendy Skills
This website measures Skills that employers seek in the IT industry. This is the only list based on employment
http://trendyskills.com/
This webpage is interactive. You can click on the bottom to view by absolute popularity, popularity by percentage, and salary. The salary numbers might be misleading. If a preponderance of jobs for a language are in California, then that salary will be available only in California.
Trendy listed a language I needed to look up: "S". S is a statistical programming language.
http://en.wikipedia.org/wiki/S_%28programming_language%29
I am familiar with a major variant of S, called "R," but S was news to me.
No matter how many languages you know, you are always wondering what you should learn next. These popularity lists might be helpful to you.
Robert
Wednesday, April 2, 2014
Software Maintenance and Message IDs
I am going to describe a couple of very bad programming practices for handling messages. These bad practices increase the cost of maintenance and lead to processing errors. See my article on the cost of software maintenance.
Here is the background: It is common for one software program to send messages through sockets to another program. It is common for the messages to have a message ID and message data. It is common for the receiving program to receive multiple messages and process the data differently for each message. It is common to test with a series of "if" statements. We will use this example:
if message.id == "MyVerySpecialMessage":
myVerySpecialMessageFuntion(message.data)
The first mistake in handling messages is to test on a substring of the full message ID string. In Python it would look like this:
if message.id.find("VerySpecial") >= 0:
myVerySpecialMessageFuntion(message.data)
This will work, but there are two problems. One is that a new message could be added later that has the message.id of "TomsVerySpecialMessage". Testing on the substring "VerySpecial" would catch this message as well and feed the data to the wrong function. The other problem is that when searching to find where in all the lines of code the message ID "MyVerySpecialMessage" is processed, you will not find this line of code because it does not use the full ID that you are using for searching. Searching code with functions like grep are the only way we can work with undocumented code. Using substrings of a message ID is an insufferable aggravation for software maintenance: don't do it.
The second mistake in handling messages is to use an else statement to implicitly handle and process a message. An else-if statement should always be used to explicitly process a message. The else statement should only be used to report unexpected and not-handled messages.
Here is a simple example. There are two message IDs: "MessgeOne" and "MessageTwo". The poor practice of processing with an else-statement looks like this:
if message.id == "MessgeOne":
messgeOneFuntion(message.data)
else:
messgeTwoFuntion(message.data)
If a message with an ID of "MessgeThree" hits this code block, it will go into the wrong function.
The proper way to handle the "MessgeOne" and "MessageTwo" example is as follows (elif is the Python way of saying "else if":
if message.id == "MessgeOne":
messgeOneFuntion(message.data)
elif message.id == "MessgeTwo":
messgeTwoFuntion(message.data)
else:
reportError( message.id)
Avoid bad programming practices. They are not outgrown. I have seen programmers with decades of experience making exactly these mistakes. Begin with good programming practices and stay with them.
Robert
Here is the background: It is common for one software program to send messages through sockets to another program. It is common for the messages to have a message ID and message data. It is common for the receiving program to receive multiple messages and process the data differently for each message. It is common to test with a series of "if" statements. We will use this example:
if message.id == "MyVerySpecialMessage":
myVerySpecialMessageFuntion(message.data)
The first mistake in handling messages is to test on a substring of the full message ID string. In Python it would look like this:
if message.id.find("VerySpecial") >= 0:
myVerySpecialMessageFuntion(message.data)
This will work, but there are two problems. One is that a new message could be added later that has the message.id of "TomsVerySpecialMessage". Testing on the substring "VerySpecial" would catch this message as well and feed the data to the wrong function. The other problem is that when searching to find where in all the lines of code the message ID "MyVerySpecialMessage" is processed, you will not find this line of code because it does not use the full ID that you are using for searching. Searching code with functions like grep are the only way we can work with undocumented code. Using substrings of a message ID is an insufferable aggravation for software maintenance: don't do it.
The second mistake in handling messages is to use an else statement to implicitly handle and process a message. An else-if statement should always be used to explicitly process a message. The else statement should only be used to report unexpected and not-handled messages.
Here is a simple example. There are two message IDs: "MessgeOne" and "MessageTwo". The poor practice of processing with an else-statement looks like this:
if message.id == "MessgeOne":
messgeOneFuntion(message.data)
else:
messgeTwoFuntion(message.data)
If a message with an ID of "MessgeThree" hits this code block, it will go into the wrong function.
The proper way to handle the "MessgeOne" and "MessageTwo" example is as follows (elif is the Python way of saying "else if":
if message.id == "MessgeOne":
messgeOneFuntion(message.data)
elif message.id == "MessgeTwo":
messgeTwoFuntion(message.data)
else:
reportError( message.id)
Avoid bad programming practices. They are not outgrown. I have seen programmers with decades of experience making exactly these mistakes. Begin with good programming practices and stay with them.
Robert
Sunday, March 16, 2014
Software Maintenance and Variables
A variable for every purpose, and a purpose for every variable. This is a useful maxim for writing maintainable, coherent software. A variable is more than a piece of computer memory used for storing data. Variables with useful names and coherent usage contribute to the meaning and structure of a program. Changing the meaning of a variable is a symptom of lazy coding that degrades the quality of the code.
Here is an example of "a variable for every purpose." I worked on one software product that had two resources (A and B) that were used with equal numbers: NumberOfA was equal to NumberOfB. The programmer made the mistake of using one variable for two purposes. Instead of using NumberOfA = 16 and NumberOfB = 16, he used NumberOfUnits = 16. Perhaps he did not make this mistake on his own. Perhaps he was directed by a code reviewer to eliminate a variable for the sake of efficiency. Some years later, the customer decided to double the number of type B hardware units in the system. So I had to read every section of code that used NumberOfUnits and change it to either NumberOfA or NumberOfB. Changing the variable declarations and initializations was easy. But the way this code was written, the variable NumberOfUnits appeared in hundreds and hundreds of places, and every instance of this variable had to be studied and modified. Every time I had to guess, due to a lack of comments, whether it was A or B hardware units that were being commanded, an element of risk was introduced into the product. What could have been a simple change, changing from NumberOfB = 16 to NumberOfB =32, turned into a laborious task that went on for hours. Time is money, and lazy programming is expensive in the long run.
Here is an example of "a purpose for every variable." One complex product I worked on had a class with an instance variable that was used for two different purposes. The same variable was used in two different operations (methods), and used for two different purposes. This was done out of sheer laziness. This worked at first because the operations did not overlap in the original releases of the code. Later on, however, new requirements from our customer required the first operation to be used again, after the second operation had changed the value of the shared instance variable. Because one variable was used for two purposes, the code was now broken and a hunt for the bug ensued. Once the problem was discovered the solution was to simply add a second variable for the second purpose.
There is nothing clever about eliminating a variable. Following the maxim, "a variable for every purpose, and a purpose for every variable," saves money. There is a difference between efficiency and laziness.
Robert
Here is an example of "a variable for every purpose." I worked on one software product that had two resources (A and B) that were used with equal numbers: NumberOfA was equal to NumberOfB. The programmer made the mistake of using one variable for two purposes. Instead of using NumberOfA = 16 and NumberOfB = 16, he used NumberOfUnits = 16. Perhaps he did not make this mistake on his own. Perhaps he was directed by a code reviewer to eliminate a variable for the sake of efficiency. Some years later, the customer decided to double the number of type B hardware units in the system. So I had to read every section of code that used NumberOfUnits and change it to either NumberOfA or NumberOfB. Changing the variable declarations and initializations was easy. But the way this code was written, the variable NumberOfUnits appeared in hundreds and hundreds of places, and every instance of this variable had to be studied and modified. Every time I had to guess, due to a lack of comments, whether it was A or B hardware units that were being commanded, an element of risk was introduced into the product. What could have been a simple change, changing from NumberOfB = 16 to NumberOfB =32, turned into a laborious task that went on for hours. Time is money, and lazy programming is expensive in the long run.
Here is an example of "a purpose for every variable." One complex product I worked on had a class with an instance variable that was used for two different purposes. The same variable was used in two different operations (methods), and used for two different purposes. This was done out of sheer laziness. This worked at first because the operations did not overlap in the original releases of the code. Later on, however, new requirements from our customer required the first operation to be used again, after the second operation had changed the value of the shared instance variable. Because one variable was used for two purposes, the code was now broken and a hunt for the bug ensued. Once the problem was discovered the solution was to simply add a second variable for the second purpose.
There is nothing clever about eliminating a variable. Following the maxim, "a variable for every purpose, and a purpose for every variable," saves money. There is a difference between efficiency and laziness.
Robert
Wednesday, February 26, 2014
Python GUIs with PyGTK and Glade
PyGTK is a system for developing GUIs in Python. PyGTK runs on Linux and on Windows. Glade is a free graphical GUI builder for use with GTK. Glade can run on Windows or Linux. It is important to know that PyGTK does not yet run with Python 3. I uninstalled my Python 3 and installed Python 2.7.5 because PyGTK will run with Python 2.7. You must have a compatible Python when using PyGTK. I got Python 2.7.5 from this website. Then I downloaded the pygtk-all-in-one-2.24.0.win32-py2.7.msi installer from this website. This package comes with Glade.
You can write GUI code by writing code in PyGTK in the same fashion you can write code to create GUIs with Tkinter, which now comes bundled with Python. But once you get used to using a graphical GUI designer like Netbeans, you will want to use a tool like Glade.
There are tutorials available for PyGtk. One example of a good tutorial that comes with sample code is the tarball pygtk2tutorial.tgz that can be downloaded from the website http://www.moeraki.com/pygtktutorial/index.html Look for the link named "Gzip'd Tarball of Tutorial (1.42 MB)". Once you unzip it, go into the folder pygtk2tutorial and double-click on index.html to read the tutorial with your web browser. The example code is in the folder pygtk2tutorial\examples.
This kind of support makes Python a great language, for beginners and professionals alike.
Robert
You can write GUI code by writing code in PyGTK in the same fashion you can write code to create GUIs with Tkinter, which now comes bundled with Python. But once you get used to using a graphical GUI designer like Netbeans, you will want to use a tool like Glade.
There are tutorials available for PyGtk. One example of a good tutorial that comes with sample code is the tarball pygtk2tutorial.tgz that can be downloaded from the website http://www.moeraki.com/pygtktutorial/index.html Look for the link named "Gzip'd Tarball of Tutorial (1.42 MB)". Once you unzip it, go into the folder pygtk2tutorial and double-click on index.html to read the tutorial with your web browser. The example code is in the folder pygtk2tutorial\examples.
This kind of support makes Python a great language, for beginners and professionals alike.
Robert
Sunday, October 13, 2013
The Purpose of this Blog
If your child is interested in computer programming, I have started this blog to assist you. This is why there are some articles on which is the best first language for a beginner. The slant is for beginners, but there is some information for programmers in general.
I will also share items of interest related to software.
Robert
I will also share items of interest related to software.
Robert
Self Documenting Code and Ecclesiastes
In a previous article, Cost of Software Maintenance, I denigrated self-documenting code. Because so many people believe in it, I should discuss it further.
Code changes, but documentation is usually not updated to keep pace with the code changes. Documentation becomes increasingly outdated. This is one reason given for skipping documentation. Another reason is the lack of time or money when first writing the code. Limited resources is a legitimate reason to minimize documentation. Many believe that time-to-market is so important that documentation must be sacrificed. Frankly, many programmers have trouble writing. You do not see many English majors coding software.
Alexis Ohanian said in Without Their Permission that he and his partner worked day and night for a month to create a website that was "only slightly embarrassing." He also said, "...if you are not a little embarrassed by what you launched, you waited too long. It need only be good enough to be useful" (page 62). He is not alone in saying this. I remember hearing the president of Rogue Wave saying at a conference that if you spend too much time adding quality to your product, you will lose market share to a company that can get a less refined product out to market more quickly and take the market.
On the other hand, Crossing the Chasm by Geoffrey A. Moore describes the problem companies have of breaking out of the early-adopter ghetto. When your product barely works and customers want a solid product, your growth is blocked. Early adopters want the latest technology and they are willing to wait for quality to improve. Lack of documentation can make it impossible to improve the product and expand your market share. I saw one company try to out-source documentation of existing software to a company in Albania because the foreign programmers were cheaper. It did not work. Company growth was stymied because new staff took too long to decode the code and the outsourcing of documentation failed.
If use of self-documenting code will solve the documentation problem, then that would be great. But what is self-documenting code? The best approach is to use a documentation generator that creates HTML documentation from properly formatted comments. Javadoc for Java and Pydoc for Python are examples. The worst approach is number one on this list: using meaningful names for variables and functions. Meaningful names, with no comments, is very cheapest form of self-documenting code. The following section explains how this breaks down.
Ecclesiastes
The book of Ecclesiastes says in 1:15, "What is twisted cannot be straightened; what is lacking cannot be counted." The problem with meaningful names is that a number of programmers suffer from twisted logic and a faulty-world view. Let me give you a real example, altered to protect the identities of those involved.
I was asked to modify Product X to issue new commands to hardware devices. Only one device at a time was turned on and I needed to tell the code to find which device was turned on and then command it. I found an undocumented function named getActiveDevice. After I modified the code I went to the customer site to test it against the real devices. The code changes did not work because the undocumented function getActiveDevice did not keep track of which device was turned on (my interpretation of Active), but it kept track of which device had a display visible on the GUI. (The GUI changed the devices that were visible depending on which tab was selected.) The function should have been named getVisibleDevice. The world-view of the previous programmer was not a view of the customer product, but a view of the programmer's GUI code. The real world was not used as a point of reference by the previous programmer, so the variable names and function names were divorced from reality and were less than useless.
You cannot count on variable names or function names to tell you what is going on in the code if the coder used twisted logic or a faulty-world view. If there is no documentation, and the code has no comments, and when you object you are told that the code is self-documenting, then they are "shining you on." Documentation generators like Javadoc or Pydoc require comments. If self-documented code is done properly, there are meaningful comments in the code that document generators turn into HTML documents. You cannot count on meaningful names alone to document the code.
Robert
Code changes, but documentation is usually not updated to keep pace with the code changes. Documentation becomes increasingly outdated. This is one reason given for skipping documentation. Another reason is the lack of time or money when first writing the code. Limited resources is a legitimate reason to minimize documentation. Many believe that time-to-market is so important that documentation must be sacrificed. Frankly, many programmers have trouble writing. You do not see many English majors coding software.
Alexis Ohanian said in Without Their Permission that he and his partner worked day and night for a month to create a website that was "only slightly embarrassing." He also said, "...if you are not a little embarrassed by what you launched, you waited too long. It need only be good enough to be useful" (page 62). He is not alone in saying this. I remember hearing the president of Rogue Wave saying at a conference that if you spend too much time adding quality to your product, you will lose market share to a company that can get a less refined product out to market more quickly and take the market.
On the other hand, Crossing the Chasm by Geoffrey A. Moore describes the problem companies have of breaking out of the early-adopter ghetto. When your product barely works and customers want a solid product, your growth is blocked. Early adopters want the latest technology and they are willing to wait for quality to improve. Lack of documentation can make it impossible to improve the product and expand your market share. I saw one company try to out-source documentation of existing software to a company in Albania because the foreign programmers were cheaper. It did not work. Company growth was stymied because new staff took too long to decode the code and the outsourcing of documentation failed.
If use of self-documenting code will solve the documentation problem, then that would be great. But what is self-documenting code? The best approach is to use a documentation generator that creates HTML documentation from properly formatted comments. Javadoc for Java and Pydoc for Python are examples. The worst approach is number one on this list: using meaningful names for variables and functions. Meaningful names, with no comments, is very cheapest form of self-documenting code. The following section explains how this breaks down.
Ecclesiastes
The book of Ecclesiastes says in 1:15, "What is twisted cannot be straightened; what is lacking cannot be counted." The problem with meaningful names is that a number of programmers suffer from twisted logic and a faulty-world view. Let me give you a real example, altered to protect the identities of those involved.
I was asked to modify Product X to issue new commands to hardware devices. Only one device at a time was turned on and I needed to tell the code to find which device was turned on and then command it. I found an undocumented function named getActiveDevice. After I modified the code I went to the customer site to test it against the real devices. The code changes did not work because the undocumented function getActiveDevice did not keep track of which device was turned on (my interpretation of Active), but it kept track of which device had a display visible on the GUI. (The GUI changed the devices that were visible depending on which tab was selected.) The function should have been named getVisibleDevice. The world-view of the previous programmer was not a view of the customer product, but a view of the programmer's GUI code. The real world was not used as a point of reference by the previous programmer, so the variable names and function names were divorced from reality and were less than useless.
You cannot count on variable names or function names to tell you what is going on in the code if the coder used twisted logic or a faulty-world view. If there is no documentation, and the code has no comments, and when you object you are told that the code is self-documenting, then they are "shining you on." Documentation generators like Javadoc or Pydoc require comments. If self-documented code is done properly, there are meaningful comments in the code that document generators turn into HTML documents. You cannot count on meaningful names alone to document the code.
Robert
Subscribe to:
Posts (Atom)