My oldest son is back in college and currently working on a really long programming assignment. The course requires him to use the Java programming language and he is not very happy about it. At the beginning of the project, he was told by the teaching assistants that his code would approach 5,000 lines of code and take 3 weeks to write. Part of the reason for the class is to show the flexibility of Java. My son doesn't see it that way. His preference would have been to use Erlang. He could do everything the 5,000-line Java program does with 25 to 30 lines in Erlang.
This brings up the topic of programming languages. Not all of them are created equal. If you want to write something that runs very fast and only needs to run on one platform, do it in Assembly. If you need something to run as fast as possible but it may run on a number of different operating system (i.e. Linux, Windows, or Mac), then use C. If you are working with statistics then R is your best choice. A good software developer will know the benefits of a number of different languages and apply the best one for the problem at hand.
Does that mean that every software developer should know every language out there? No, but he or she should be familiar with a number of different languages along with the strengths and weaknesses of each. Software developers should also be experimenting with new languages when time permits and not rely on one language to do everything. After all, 30 lines in one language is a whole lot less work than 5,000 even if you have to learn a new language. The 30 lines of code is also a lot easier to maintain.
Showing posts with label C++. Show all posts
Showing posts with label C++. Show all posts
Wednesday, October 22, 2014
Wednesday, January 22, 2014
A Little Coding
It has been a while since I have done any real computer programming. Sure I work on a computer all day and spend a lot of time writing SQL statements but I don't really count SQL as a programming language. I figure I have been getting a little rusty and so I have taken it upon myself to do a little coding every evening when I get back to the boat. When I am at home in Utah, there is too much to do each evening. When I am on the boat in California, there is nothing to do but watch television. I figure it is a good time to refresh my programming skills.
It is best to start with what I already know and so I have a simple example C program that converts IP addresses into integers. An IP address is simply 4 numbers separated by a dot. My IP address is something like "101.102.103.104". This can be converted into an integer simply by breaking the numbers up and thinking of them in binary format (that will be in 1's and 0's). If you take 101 as a decimal number and shift it to the left by 24 bits, add it to 102 shifted to the left by 16 bits, add it to 103 shifted to the left by 8 bits, and add it to 104, you are left with an unsigned 32-bit integer that is the equivalent of your IP address. This is a number between 0 and 4,294,967,295.
Now the question you need to ask is why? Isn't it easier to remember 101.102.103.104 than some seemingly random integer? Yes, but it also takes more space. The IP address requires up to 16 bytes when left as a string. The unsigned integer only requires 4 bytes. With computers that have gigabytes of memory, does 12 bytes really matter? Yes, when you are trying to remember 90 million IP addresses. 4 times 90 million is only 360 megabytes of memory where 16 times 90 million is well over a gigabyte.
My little program is working in the C programming language because that is what I am most familiar with. Now my goal is to rewrite it in a number of other languages so I can become familiar with them. When I am finished, I want to compare execution times and see which is fastest. I also want to see which one is easiest to understand, easiest to code, and fewest number of lines. It may sound like a boring exercise but my hope is that it will help improve my coding skills at the same time I learn about a number of new languages. It also has a practical application to a problem I am trying to solve at work and so that makes it significantly more interesting.
It is best to start with what I already know and so I have a simple example C program that converts IP addresses into integers. An IP address is simply 4 numbers separated by a dot. My IP address is something like "101.102.103.104". This can be converted into an integer simply by breaking the numbers up and thinking of them in binary format (that will be in 1's and 0's). If you take 101 as a decimal number and shift it to the left by 24 bits, add it to 102 shifted to the left by 16 bits, add it to 103 shifted to the left by 8 bits, and add it to 104, you are left with an unsigned 32-bit integer that is the equivalent of your IP address. This is a number between 0 and 4,294,967,295.
Now the question you need to ask is why? Isn't it easier to remember 101.102.103.104 than some seemingly random integer? Yes, but it also takes more space. The IP address requires up to 16 bytes when left as a string. The unsigned integer only requires 4 bytes. With computers that have gigabytes of memory, does 12 bytes really matter? Yes, when you are trying to remember 90 million IP addresses. 4 times 90 million is only 360 megabytes of memory where 16 times 90 million is well over a gigabyte.
My little program is working in the C programming language because that is what I am most familiar with. Now my goal is to rewrite it in a number of other languages so I can become familiar with them. When I am finished, I want to compare execution times and see which is fastest. I also want to see which one is easiest to understand, easiest to code, and fewest number of lines. It may sound like a boring exercise but my hope is that it will help improve my coding skills at the same time I learn about a number of new languages. It also has a practical application to a problem I am trying to solve at work and so that makes it significantly more interesting.
Tuesday, October 30, 2012
Object-Oriented Programming
Object-oriented programming was all the rage twenty years ago. Traditional programming languages like "C" evolved to "C++" or Objective-C and included these new extensions. Software developers jumped on the bandwagon and extolled the virtues of this huge "paradigm shift." So what was all this hype about? Creating reusable code.
Fast forward to today and object-oriented program is still popular. It just isn't stressed as much as when it first arrived. The same can be said about air conditioning in automobiles. It used to be a luxury but now comes standard in most new vehicles. So twenty years later we have to ask if this once new enhancement has delivered on all of its promises.
The original selling point of reusable code was that software developers could build small little programs that could be put together to build larger systems. That is something that has been realized, albeit a little differently than originally thought. Today we have a number of building blocks that developers don't have to recreate when coding complex software. Companies like Google, Twitter, and LinkedIn have created software like Hadoop, Storm, and Kafka. These programs can then be used to make larger systems. This is helping developers throughout the world. So has object-oriented programming delivered? I would have to say, "YES!"
Fast forward to today and object-oriented program is still popular. It just isn't stressed as much as when it first arrived. The same can be said about air conditioning in automobiles. It used to be a luxury but now comes standard in most new vehicles. So twenty years later we have to ask if this once new enhancement has delivered on all of its promises.
The original selling point of reusable code was that software developers could build small little programs that could be put together to build larger systems. That is something that has been realized, albeit a little differently than originally thought. Today we have a number of building blocks that developers don't have to recreate when coding complex software. Companies like Google, Twitter, and LinkedIn have created software like Hadoop, Storm, and Kafka. These programs can then be used to make larger systems. This is helping developers throughout the world. So has object-oriented programming delivered? I would have to say, "YES!"
Labels:
C,
C++,
Hadoop,
Kafka,
object-oriented programming,
Objective-C,
storm
Monday, June 27, 2011
Relearning C
The first computer language I learned was BASIC and I was in the 8th grade. It was fun to get the computer to do various things but I really enjoyed my next class which taught me Pascal. When I got to college, I learned a few more computer programing languages including C. I would have to say that C remains as my favorite language for a number of reasons.
Recently I started a new personal project and have chosen to do it in C. I thought about using something a little more modern like Python or Perl but need something that compiles to an incredibly fast program. The tradeoff is that I will have to spend more time writing code. It also means I will have to relearn many of the things I have forgotten about C.
C is one of those languages that has a lot of flexibility but also has a lot of pitfalls. Today I was working with pointers and made a minor mistake on the syntax. Because pointers are so flexible, the syntax was correct, I just wasn't getting the results I was expecting. I used an Internet search engine to look up various examples with no success. It turns out, I needed to include some parenthesis around one small section of code. I came up with the solution after thinking about the results I was getting for a while. Then things started working correctly.
Some might be discouraged by such an experience, but not me. I just realized that I need to do some relearning and that is one of the reasons I started this project. It is my understanding that colleges and universities have moved towards teaching Java instead of C and I think that is a mistake. If it was up to me, everyone would learn C as their first computer programming language. There is something about having to work hard to get your program running. It has a bit of a learning curve, but allows you to write complex programs that run really fast.
Recently I started a new personal project and have chosen to do it in C. I thought about using something a little more modern like Python or Perl but need something that compiles to an incredibly fast program. The tradeoff is that I will have to spend more time writing code. It also means I will have to relearn many of the things I have forgotten about C.
C is one of those languages that has a lot of flexibility but also has a lot of pitfalls. Today I was working with pointers and made a minor mistake on the syntax. Because pointers are so flexible, the syntax was correct, I just wasn't getting the results I was expecting. I used an Internet search engine to look up various examples with no success. It turns out, I needed to include some parenthesis around one small section of code. I came up with the solution after thinking about the results I was getting for a while. Then things started working correctly.
Some might be discouraged by such an experience, but not me. I just realized that I need to do some relearning and that is one of the reasons I started this project. It is my understanding that colleges and universities have moved towards teaching Java instead of C and I think that is a mistake. If it was up to me, everyone would learn C as their first computer programming language. There is something about having to work hard to get your program running. It has a bit of a learning curve, but allows you to write complex programs that run really fast.
Labels:
C,
Computer Programming,
programming languages
Monday, January 4, 2010
A New Year
Christmas has been cleaned up and the new year has come. Now it is time to think about how to make this one better than the last. Perhaps it might help if I take a quick look back at 2009 and see how I grew, if at all. Then I can set goals to make the coming year better.
2009 can best be described as the year that I spent working on my kiosk project. The software is done and now my partners and I are waiting for a large company to buy it and increase the number of users. The software is already in limited production and so we know it works. We would just like to see it work for more people.
2009 was also the year I spent preparing for a two-week backpacking trip at Philmont Scout Ranch in New Mexico. My oldest son and I spent countless hours doing practice hikes to help prepare for this adventure in the wilderness. Unfortunately it had the nasty consequence of burning down several money making opportunities. I don't regret my decision to spend quality time with my seventeen-year-old son, but my hope is that 2010 will be the year that helps me fully recover. I have some interesting prospects already and the year is only four days old.
2009 was the year I finally broke down and started to blog (as evidenced by this entry). I had been thinking about the idea for years but never done it. Then I read an important piece of e-mail that served as the catalyst to go through the simple process of setting up a blog. Now I just need to keep it up.
In the back of my mind I have been tossing around some resolutions or goals for the new year. There are certain parts of my life that are practically perfect and I don't want to change those. For instance, I get more than enough skiing in every year and so I don't need to set any goals about how many days I will ski this year nor do I need to have a goal about visiting new resorts.
While some parts of my life are perfect, others are not. I recently worked on a one-day project involving the C programing language and discovered that some of my skills have atrophied. Maybe I need to pull out The C Programming Language by Kernighan and Ritchie to help brush up on some fundamentals. Or maybe I need to find a good web-based tutorial on threaded programming and convert some of my projects to use threads (threads can make programs faster and smaller when done correctly).
Perhaps 2010 is the year I break down and try something completely new. I might try to learn a new computer language like Ruby, which seems to be gaining more mainstream acceptance. OK, that is not completely new as I already know several computer languages and one more really isn't that different. Istead I might try learning a language like Russian, Portuguese, or Chineese.
I'm not sure how 2010 will turn out but I do know that it has a lot of potential. All I need to do is keep moving in a forward direction and not let myself fall into a routine that halts any progress. May this new year be a great one for all of us.
2009 can best be described as the year that I spent working on my kiosk project. The software is done and now my partners and I are waiting for a large company to buy it and increase the number of users. The software is already in limited production and so we know it works. We would just like to see it work for more people.
2009 was also the year I spent preparing for a two-week backpacking trip at Philmont Scout Ranch in New Mexico. My oldest son and I spent countless hours doing practice hikes to help prepare for this adventure in the wilderness. Unfortunately it had the nasty consequence of burning down several money making opportunities. I don't regret my decision to spend quality time with my seventeen-year-old son, but my hope is that 2010 will be the year that helps me fully recover. I have some interesting prospects already and the year is only four days old.
2009 was the year I finally broke down and started to blog (as evidenced by this entry). I had been thinking about the idea for years but never done it. Then I read an important piece of e-mail that served as the catalyst to go through the simple process of setting up a blog. Now I just need to keep it up.
In the back of my mind I have been tossing around some resolutions or goals for the new year. There are certain parts of my life that are practically perfect and I don't want to change those. For instance, I get more than enough skiing in every year and so I don't need to set any goals about how many days I will ski this year nor do I need to have a goal about visiting new resorts.
While some parts of my life are perfect, others are not. I recently worked on a one-day project involving the C programing language and discovered that some of my skills have atrophied. Maybe I need to pull out The C Programming Language by Kernighan and Ritchie to help brush up on some fundamentals. Or maybe I need to find a good web-based tutorial on threaded programming and convert some of my projects to use threads (threads can make programs faster and smaller when done correctly).
Perhaps 2010 is the year I break down and try something completely new. I might try to learn a new computer language like Ruby, which seems to be gaining more mainstream acceptance. OK, that is not completely new as I already know several computer languages and one more really isn't that different. Istead I might try learning a language like Russian, Portuguese, or Chineese.
I'm not sure how 2010 will turn out but I do know that it has a lot of potential. All I need to do is keep moving in a forward direction and not let myself fall into a routine that halts any progress. May this new year be a great one for all of us.
Subscribe to:
Comments (Atom)
