Spheriosity Work Continues

January 5, 2009

This is just a quick update about my recent work on Spheriosity. I had promised myself that I would release a version over my winter break from college. Today I finally had time to sit down with the code and start working through a few bugs. I fixed most of the bugs that I know about, and now I have moved on into commenting and writing unit tests.

It was a bit of a struggle to motivate myself to write the current group of units tests, which is probably why they aren’t already written. I will write them though, and it will help keep Spheriosity more stable in the long run so it’s a worthwhile goal.

After the unit tests are done I plan to add one last feature which will handle midpoints of lines. This should be a snap to implement and it has been on my list for a while.

Finally, I will do a major update to the user documentation which will include a proof reading πŸ™‚ .

After all that I will release the new version. I’m not sure whether I consider this alpha or beta. I’m going to have to give it some more consideration. It looks pretty likely that I will finish this all within the next two weeks so hopefully all goes according to plan πŸ™‚ .

Advertisements

Is C++ an Elitist Language?

August 9, 2008

Recently I made a post about some things in Java that I find to be a bit of an issue. The artcle was reposted on Javalobby and it started an interesting discussion in the comments section. Among other things, one comment in particular struck me as disconcerting:

When you use a language you should ask yourself what is the feeling of it. C++ is an elitist language with strong roots in the procedural C (that should compile in C++), and a big focus on performance. JavaΒ  is a full Object Oriented langage inspired mainly by C++ and smalltalk, which was for a long time pretty slow, and focus on writing big maintainable programs via simplicity and strong typing. ( A comment by Raphael_Lemaire @ http://java.dzone.com/articles/sometimes-java-makes-me-sad )

Specifically the part about C++ being elitist. Now, I love C++, so of course I am biased. However, I never thought of it as being elitist. The funny thing is that the syntax of C++ is very close to that of Java, does that mean Java is elitist? As far as I see it the real difference is that Java: offers you loads of libraries, memory management, and it allows the coder to not have to think about pointers. Lets look at each of these issues.

The first issue, of libraries, I don’t really consider much of an issue. Especially if you use open source libraries there are hundreds of libraries which are readily available. Certainly the Java libraries are nice, and most, if not all, are guaranteed to be cross platform. However, many of the C++ ones are as well so I also consider that argument to be a moot point. The fact that you have to compile them for eachΒ  different platform can be a problem at times, but I consider it a minor problem especially given the speed of modern computers.

The second issue of memory management is something that goes to Java’s favor. I think, however, that it is a minor issue in the scheme of things. Once you understand the basic idea of memory management, and as long as you use a good programming style which favors allocating and freeing memory in the same place, this isn’t as big of a deal. I have written that you can leak memory in Java too, so Java is not free of this nuisance either! Therefore Java coders who think that are impervious to problems with memory are just kidding themselves.

Third is the fact that in Java you don’t deal with pointers. Or, rather, you don’t have to think about them even though you deal with them all the time. This is more personal opinion than anything, but I never found pointers to be that difficult of a thing to deal with. Once you get an understanding of them it’s really a trivial matter. I know that some people make a fuss because you have to always be thinking ‘is this a pointer to an object, or the object’, but that consideration has never slowed me down. You make note of it once and then it stays the same throughout.

So what is it about C++ that makes it elitist? Is it the people that write code so convoluted that only an experienced pro can read it? I think this could be a big part of it. No matter what language you use people can always write unnecessarily confusing code. Languages like Java try to help prevent this, but I’m sure it can still be done. Having access to pointers can lead to code that is difficult to read, but I think the problem there has more to do with the coders than the language. Programmers should be wise enough to write readable code, and not blame the language.

Do you blame English when you can’t spell a word? I mean… silent letters, what is up with that? No, you probably blame yourself for not having put in enough time to learn the proper spelling. So why should we blame C++ for people that write obfuscated code? At the end of the day it all comes down to the coder, and whether they want to write good code or not.

The bottom line is that I don’t consider C++ an elitist language,Β  but rather a language that with some extra consideration can be just as easy to code in as Java.


Sometimes Java Makes Me Sad

August 1, 2008

On any given day I go back and forth as to whether I truly like Java as a language or not. On one hand the automatic memory management is really quite nice. However it has it’s downsides. Normally I find little quirks of the language that I really wish it had. First off, Java does not have unsigned integers. Now, this is not a true tragedy, and one can work around this by using long integers and bit operations. However that is normally too much work when one is just looking for a safer type.

Another downfall of Java is the pointer hiding. There are times when I really really want to be able to see exactly what is going on. (Yes I know every object is technically a pointer) There is one place in particular this has come to annoy me. I was trying to have a function change the value of an int. This would be quite easy in C or C++, but in Java it is rather tricky. Since you can’t pass the int as reference (Java only has pass by value) and the Integer class is Immutable. One hack I found was to declare an int array with a single element and pass that to the function:

public class TesterClass
{
    public static void main(String args[])
    {
     int[] fooArray = new int[1];

     fooArray[0] = 42;

     System.out.println("My val == " + fooArray[0]);
     myFunc(fooArray);
     System.out.println("My val == " + fooArray[0]);
    }

    public static void myFunc(int[] changeMe)
    {
     changeMe[0] = 12345;
    }

}

Which brings me to my next topic… why is the Integer class immutable!? Say I have the Integer class inside an ArrayList. Well I can’t simply change the value of that Integer. Why? Well because the creators of Java feel the Integer class should be immutable. To me, this makes no sense at all. Yes, I could simply make my own Integer class which allows for changing the underlying value, but why should I? Isn’t this a basic feature that it should have?! It could just have a .setValue() function. Simple! In my mind this makes using the primitive wrappers inside an ArrayList rather useless because you’d have to remove and insert them all the time if you have to change their values. Now, perhaps this is how the creators of Java wanted it. I suppose I will never know.

Overall I do like Java as a language, but sometimes I get discouraged by the potential issues of speed loss, and by some of the things I mentioned above. The control C++ gives the coder is hard to give up, and for now C++ will remain my favorite language πŸ™‚


Reading all the Documentation…

July 19, 2008

So apparently when people the time to write something down they wrote it down for a reason. I happened to have missed this simple fact recently when I was working on some Python scripts. I was trying to separate the scripts into different folders based on what they did. Simple enough, but then I ran into the issue of certain scripts needing to go around folder boundries. Of course, Python supports this feature using it’s import system.

This is where my trouble was. I was reading the article about how import works from the standard Python docs. So I read as much as I thought I needed and skipped over, what I thought at the time, to be unimportant. As it turns out the ability to do relative imports using ‘..’ is a feature of only Python 2.5 *sigh*. Alright, so I could have just installed Python 2.5, but I didn’t want to limit this code to running on Python 2.5 for no good reason. So I went back and changed the code to using absolute imports which took around 30 minutes because there were a decent number of files to play with.

So how did I miss this in the documentation? Well I managed to skim over the part which mentions this is only for Python 2.5 (I blame myself for this, btw). I take this as a lesson to pay closer attention when reading documentation. It may have taken me an extra 5 or 10 minutes to read all the documentation about imports and Python… but I will would have saved half an hour of my time if I had taken the extra effort πŸ™‚


The Importance of White Space in Code

July 18, 2008

For almost as long as I have been writing code I have tried my best to improve upon my coding style. This is, of course, an area of much controversy among computer scientists. What makes “good” style? Sometimes its purely a matter of opinion. What I find easy to read might not be so easy for someone else. I suppose this is one reason you might argue that programmers should all try and adhere to similar styles. This way any code would be just as readable to anyone.

Almost every language I have ever used allows you to put in more white space than you need, and anywhere you want to. I find this to be quite a useful feature. Not because I think it allows me to write better algorithms, but because it helps me organize the code and suggest certain things to the reader. To some degree making readable code is very much an art [one that I do not claim to have mastered]. I think adding white space in blocks of code to segment it into different sections is good practice. Lets take the following C code for example. Keep in mind that this could be any language and the same concepts apply:

#include <stdio.h>
#include <stdlib.h>
int main(int argv,char** argc)
{
  int x;
  int y;
  int sum;
  for(x=0;x<10;x++)
  {
    for(y=0;y<10;y++)
    {
      sum=x+y;
      sum=sum+x*x+y*y;
      printf("Random number is %d\n",sum);
      printf("yay for loops\n");
    }
  }
  exit(0);
}

Now, I will be the first to admit that this code is fairly random and doesn’t do anything of extreme usefulness, but that is not the point here. Notice this same program with a little extra white space added:

#include <stdio.h>
#include <stdlib.h>

int main(int argv, char** argc)
{
  int x;
  int y;
  int sum;

  for(x = 0 ; x < 10; x++)
  {
    for(y = 0; y < 10; y++)
    {
      sum = x+y;
      sum = sum + x*x + y*y;

      printf("Random number is %d\n", sum);
      printf("yay for loops\n");
    }
  }

  exit(0);
}

To me, this now really pops out at you, and it is much easier to see the different “areas” of this code. You have the #includes which are separated from main. This lets you know when the real code begins and puts a break between the includes and the actual code. It suggests a change in context! The next place I added white space was between the arguments in the header to main. This allows the variables (argc and argv) to stick out more to the eye.

In the actual function I put a space after I declared all the variables. Again, I use the idea that with the return we will have a change of context going from variable definitions to more concrete code. In each for loop I separated the different parts of the loop constraints to make them a tad easier to read.

Within in the inner for loop I added the most space. First I separated the mathematical statements from the print statements. You may not always want to do this because sometimes you might group a print statement for a specific calculation with the rest of the calculation, it all depends on what you are trying to say. Next I separated the different parts of the second equation to bring out the more
interesting parts. Sometimes I will add parenthesis to really be explicit as to what I am trying to do, but this didn’t see to warrant that.

Finally at the end I separated the exit(0) from the end of the for loops because it is not really part of that block of code.

So there you have it. This is a bit of a trivial example, but I think it shows that a little white space can go a long way in bringing things out to a foreign reader. Remember, the new person who reads your code will be looking for any hints they can get as to its functionality. When you are writing the code you may not need the white space to understand what is going on. However, 6 months later it
could even help you figure out what was originally intended as well as the newcomer to the code base! There’s plenty of other tricks to help make code more readable: descriptive variables, good function names, good functional decomposition, etc. I just wanted to point out one area that I think can be easily overlooked πŸ™‚


BROWNIES! — The Programmer’s Moment

July 8, 2008

There I was… testing my Python scripts to remotely adminster the radio station computers. I had been coding for a few hours trying to add support for remote admin logins. This required having the server send a public encryption key, letting the client get the potential password from the user, encrypting it with the key, sending it back to the server, having the server decrypt the potential password. Then… I saw it: “Password is:brownies”Β  shining brightly in the terminal running on the server. Proof of success at long last!

It is that feeling that I call ‘The Programmer’s Moment’ it’s a feeling of overwheling success because you just spent x amount of time on a feature, and you are finally convinced it is going to work like you planned. I am sure other professions experience this same sense of accomplishment, but I experience this most frequently when I am coding. It’s that feeling that makes long nights (or days) staring at a screen worth anything at all. It can motivate you to continue coding and keep you from giving up on a project that seems hopeless.

Here is a little screen shot of that terminal with such simple text that brought some happiness to this crazy coder πŸ™‚

Finally... got the password being sent over the network

Finally... got the password being sent over the network


My first real experience writing user docs

July 4, 2008

So today at 10:00am I embarked upon my first real attempt at writing user documentation. Spheriosity has been long overdue for some good user documentation. After all, the whole purpose of the application is to help people understand spherical geometry, so if they can’t use it then the program is worthless.

I decided that the best choice for writing the documentation was going to be LaTeX my favorite text processing language. I fell in love with LaTeX when I saw how it could format mathematical equations with ease. I use it almost 100% these days and it makes the most beautiful looking documents! It is suited perfectly for a code oriented person like myself as well because at times it feels like I am programing the document more than anything. Perhaps I will write more about LaTeX some other time.

Also because of LaTeX I realized that I might be able to run latex2html on the document and thus have something I could post on the internet. I have never been a complete fan of the output of latex2html mainly because I think it should have an option to let you view an entire section at once. I’m sure that for some things it is quite nice that it splits up into subsections and then subsubsections if you use them, but for this it doesn’t translate well.

I found that I don’t really mind writing user documentation as much as I thought I would. It’s kind of like commenting code to me. I know a lot of people don’t really enjoy commenting, but it never bothered me much. I feel like it is taking the necessary steps to ensure another human, or possibly myself, will be able to some day figure out what I was thinking. After spending lots of time writing a piece of code it seems worth it to put in that extra effort. I feel the same way about documentation. If it is able to help even a few users work with my application then I consider it well worth the effort. So far I have created 28 pages of documentation. Now, it is not solid text because there are pictures of the program as I try to visually walk the user through certain steps.

I spent a good 10 or 11 hours writing the documentation and I need to take a break from it for sure πŸ™‚ Tomorrow will be a new day and I hope to finish the documentation and place the new alpha build on SourceForge. I don’t know if I could write user documentation all day every day, but it is good to know that I can do it when I need to. I admit that I felt a bit bad not writing any code all day (except a small perl script), but it was for a good cause.

I had a bunch of good ideas about things to write about today so hopefully I will have some material for the next few days. That’s it for today though… I need to get some sleep πŸ™‚