Saturday, May 23, 2009

IDE's, Please...

When I got my internship for the summer, I began using Microsoft's Visual Studio pretty heavily. Before this I had had some experience with Dev-C++, but mostly I had just dealt with Eclipse. I found Eclipse to be useful, but it was a little hard to learn. Of course, it is open source, which makes it attractive to many programmers. I hear a rumor Visual Studio may also become open source, and will be available on Linux; I don't know where to even begin there. IDE's can be of great help, I know that I use VS for debugging, finding references, going to definitions, and the good ol' Intellisense every day. Basically, if you are working on a large project, an IDE is a must. I've posted some links below on some forum conversations about IDE's, feel free to take a look.

ProgrammingForums


CodeCall

Friday, May 15, 2009

Programming, or Just Hacking?



The business world can be a rough place for a developer. It seems client demands, under-staffing, and deadlines can make the most elegant and clean programmer a little dirty. Or a lot dirty.

While the simplest solution is often the best, their is a big line between doing something the simple, inventive way and programming a shoddy hack that will probably cause crashes later. Modularity is a wonderful thing, but often you don't have the time to make a nice friendly interface or too because you are assigned four things at once and you have to get them done and wrapped into the new version of your software. You always have to evaluate how much time you are saving in the short run, and how much time you are losing in the long run. Two weeks of development followed by months or arduous support debugging is quite the nightmare. Often you also have to think ahead of your employer, odds are they will want functionality in your software that it may or may not be designed for. Modularity can greatly aid when adding plugins.

The question after you have to ask before you start coding your solution is: AM I A PROGRAMMER, OR A HACKER? WELL ARE YA PUNK???

Saturday, May 9, 2009

pass the variable, please


One property that has tremendous bearing on any programming language is how variables are passed. There are generally two methods, passing by reference and passing by value.

Passing by reference takes the memory location of the variable or pointer and passes that into the function that takes the parameter. In short, this means that any work or changes done to the object or primitive is changed for good.

The other method is passing by value. This copies the reference to the object or variable and passes it in to the function. This allows for manipulation with the data from the variable or object without changing the actual contents of the data.

Both of these methods are valuable, and in my opinion the languages that can do both (like C#) are especially useful. In fact, this is one of the differences between Java and C#, Java only passes by value, C# allows passing by reference (through the ref keyword.) Without being able to pass by reference, Java becomes a more strongly-typed langauge, you have to go further to manipulate actual data. However, this also makes a simple program like swapping two string variables inordinately complicated compared to languages that pass by reference.

Knowing which technique the language you are using implements is of primary importance, failure to recognize whether a language passes by reference or by value will cause hours of frustration in seemingly inexplicable errors and unexpected return values.

Saturday, May 2, 2009

Scripting Languages



One enigmatic question that I find people often have a hard time giving a straight answer to is "What is the difference between a 'normal' programming language, such as C++, and a scripting language." This question leads to a lot of backpedalling and out spews a lot of general non-specific answers.

The term 'Scripting Language' refers to one of two different things. The specific definition refers to a programming language that controls software. An example of this would be QuakeC, which allows writing scripts for the popular fps game, Quake. Another example would be ASP, which works on the server side to dynamically generate web pages.

The generic term 'Scripting Language' refers to any language, whether used for specific applications or for general purposes, which is interpreted instead of compiled. An example of this general definition would be Python or Ruby.

"Aaah, now I get it." But what exactly is the difference between a language being compiled and a language being interpreted. An interpreted language is one that instead of compiled, is 'interpreted' and run at the same time. Essentially an interpreter is a dynamic compiler. it interprets each line of code in your program into machine code and then runs it at the moment. This contrasts to a language that must be compiled into machine code all at once and then run.

While an interpreted language runs slower, the syntax is often more powerful, interpreted languages allow for things such as implicit typing, which means you don't have to declare the types of your variables, and that you can change them on the fly. Programs or 'Scripts' often take a lot less time to write then if they were written in an a compiled language.

As a last note, I prefer the stricter definition of "Scripting Language", and generally so do programmers who use languages such as Python. If you have any expert knowledge of interpreted languages, please share below.

Friday, May 1, 2009

Answering Justin's Questions

This is a comment I put on a post at Justin's blog.

"This should be interesting, since this week was my first week as a programming intern.

* What do you do on a daily basis at your programming job?

Right now I am training a lot. There are several programs and over 250,000 lines of code that I shall be working to some extent with. The programs I need to know pretty well, the code only in sections (since it is just a summer internship.) Expect to spend months training and catching up on the project when you first get hired.

* How much time do you spend programming?

As a programmer you work with code constantly.

* What other tasks do you do besides programming?

You may also have to work with GUI components, more along the lines of graphic artist stuff, you also may have to take support calls.

* How long is your lunch break?

I eat at my desk, no one really bothers you, generally you have about an hour.

* Do people socialize or does everyone keep to themselves?

You chat throughout the day, only in short intervals tho, or at meetings, obviously you are there to work on your assigned tasks, not to socialize.

* How many people do you work with?

There is one guy who is training me who I guess I work with. There are several guys who have also trained with and are near my cubicle. I would say around 8 different people are working on different areas of the project I have a part of.

* What kind of development are you in (web, software, games, ect…)?

Meteorological software.

* What programming languages do you use the most?

Python scripting and C#.

* How long have you been programming?

about 3 years, but I have spent a lot of hours in those three years on it.

* Do you have sword fights while your code is compiling?

for 250,000 lines of code it compiles like running a program.

* Do you get to take breaks when you’re frustrated with code?

Yeah, you can switch to something else. Realistically people take smoke breaks every hour so if you need to you can take a walk or something, obviously you can't just veg out the whole day. There are other programmers you can bring in if you need to ask a question.

* Does your boss respect your job?

Yeah, generally management will never let you get as much time as you want or make the code clean the way you want it. Often you might feel frustrated because you have to hack something together instead of doing it the right way.

* Do you ever wish you were somewhere else?

I enjoy it a lot. Eight hours is a long time to be staring at a screen, tho. Still, if it is easy to focus on the project and the work.

* How much time do you spend surfing the web?

at work, a few minutes at lunch. A lot outside of work, mostly because of my blog, http://flycoder.blogspot.com.

* Is programming just like you thought it would be like before you started working in the field?

Yeah, I was a little naive about how much management wants to push the timetable and hack something together instead of writing something that is more stable and will be easier to modify.
Essentially, non-programmers generally are asking for things that may or may not be reasonable, and compromises have to be made on both sides.

Hope this helped, visit my blog at http://flycoder.blogspot.com, I am putting your link on my site! http://codejustin.com"

Tuesday, April 28, 2009

Squishing Bugs

Ick. Debugging code may be one of the most frustrating things in all of programming. Errors messages are almost always a sure-fire way to raise your blood pressure. Learning how to use debuggers and to read error messages is a valuable skill for any programmer. A good debugger is almost always a good programmer.

Generally, there are two types of errors in programming. The first kind might seem more frustrating in the beginning, but they are far easier to fix. The second might mean that there is something terribly wrong, and they can be a major pain to find.

1. Compile errors - These errors show up when you try to compile your code. Often they are accompanied by a cryptic compiler-error message like "Invalid Parameter List in Call" (this is from Ada 95.) Depending on what language you are programming in and what compiler you have these can be general, meaning anything from forgetting to import a package to sending the wrong type, to very specific, like "this needs a semi-colon." Usually these are problems with your syntax. Sometimes it is wrong, other times you just need to add something (in Java it might want you to handle some exception.) You have to get good at fixing these, because the more of a beginner you are, the more these are going to show up.

2. Run-time errors - These errors occur after you have compiled your code. Whenever you try to run your program, some kind of error occurs. The error messages for these are usually more general, but it still depends on the language and your debugger ("Segmentation Fault" in C++ is a classic.) These errors are the real problem because while they could be simple fixes, such as deleting your arrays in a language with un-managed memory, they could also be design flaws in your code.

Becoming a good debugger involves how you go about solving your bugs. Like all things, there is a right way and a wrong way to go about it. The wrong way comes naturally; The right way comes through practice and patience. Here are ten tips to help you on your quest to become a great debugger. (Of course your goal is to eventually write perfect, blissful, elegant code every time. Still, helping debug code once you have become a perfect programming life-form will endear you to the commoners.)

1. Don't Panic - It can be easy to get flustered or perplexed. Keep a level head. Go through your code systematically and logically.

2. Read the Error Messages - Often people see that they get an error and immediately go back to their code without even looking at the error message or at what line it is triggered. Often the error message and the line information can help you fix an error in 30 seconds flat. Read them.

3. Look for help online - This can be an easy way to find out if you implemented your code correctly, or if you have any simple syntax errors.

4. Use print statements - This can often be an easy way to see exactly where your code is failing (errors can often be caused in code before a later line triggers the error.) A simple "Got Here" print statement, or printing out your values, can help you quickly diagnose the problem. Remember to use .flush() or something similar to make sure the print statements print exactly when they are supposed to instead of staying in the buffer.

5. Comment out code sections - another great way to diagnose the problem. Often what you think is causing the error is only where an earlier error or miscalculation is exposed. Commenting out your latest code additions can help you focus on the right section instead of looking at overwhelming amounts of code.

6. Write test code - implementing problematic code on its own can give you a picture of whether the code itself is wrong, or whether it is having a problem working with code you have already written. It also helps you look at one chunk of code at a time.

7. Be aware of what is happening on the lower level - remember, depending on the language you are using, variables are often references to spaces in memory, not always primitives. Understanding how things are stored in memory, and how the functions you are calling work will greatly aid your debugging skills. (for instance in Java, string assignment copies the reference, not the actual information.)

8. Keep trying new things - Some people get stuck trying the same thing over and over again, unwilling to admit that they were wrong, that they need to try something different, or that they need to rethink their code. Be imaginative in your solutions, and don't be afraid to do it the long way; stalling won't help.

9. Take a Break - Sometimes you just need to walk away. Often your brain will still be working on the problem, even though you are doing something else. I can't count the times I have been talking with someone and stopped in the middle of the conversation and said "Oooohh, I should try this..."

10. Don't Give Up - Keep at it. Losing heart and giving up can ruin your coding experience. Asking for help is ok. Throwing up your hands and tossing in the towel isn't.

So go out there and squish some bugs!

Sunday, April 26, 2009

5 Ways to Become a Better Programmer

Here are five easy ways to become a better programmer. Think of these more as a mindset, rather than a checklist of things to do. If you follow these steps and make them attitudes, you will grow in programming by leaps and bounds.

1. Write Programs - Ok, I know this sounds like a no-brainer. Really though, it all starts by typing code. Often starting here can help you ask the right questions, and really help you with some of the things further down the list. Check out my post on tips and resources for coming up with programs to write.
2. Spend Time on Forums - Forums can be a great place to ask questions and learn about all kinds of programming topics. Don't worry if some of it (or a lot of it) goes over your head. Keep browsing and interact when you can. As long as you ask questions in the right manner (most programming forums have a sticky about this: READ IT!) forum-goers are generally a helpful lot. This is also a good place to do number 3...
3. Look at Other's Code - This can be a great help when you are looking for programs to write, if you are stuck in a program, or just want to learn something new. Looking at other's code can help you find shortcuts in syntax and show you quicker ways of doing things. Also, reading another person's code is an invaluable skill: Get good at it!
4. Look Up What You Don't Know - This is probably the most important one of the bunch. It works along with all of the other steps. If something goes over your head, or you can't seem to work something out, ask and research. There is so much information in the computer world it is impossible to have a handle on even half of it. Asking questions and researching any piece of information can help you learn much quicker. This is a life concept I try to implement every day. From acronyms to programming concepts, to words - If you stop to look things up, you will gain in knowledge very quickly then if you just gloss over things.

And now for some shameless promoting...
5. Read This Blog - Surfing the web in general for Programming info is a great idea. I try to point you to the good stuff to make your search a little easier and provide little tidbits of knowledge on various topics. I hope you find this blog useful.

So there you have it, five ways to becoming a better programmer. More to come in the future I am sure, but these are some concepts I have found invaluable. Happy learning...

Friday, April 24, 2009

Some classes

Just for the heck of it...

Some classes I have taken in the past:

Java

Algorithms


Architecture *password is "adda"* but you didn't hear that from me...

go ahead, check 'em out

Ruby Gems and Python Eggs








Ever need to write some code and think to yourself "Somebody has to have already written this (insert grumbling, moaning, sighing, etc.)?" Chances are, you're right. A huge help when you are starting to program on your own is finding applications that others have written that you can use and tailor to your own needs. Fortunately, there are tons of places to find these things on the web.

Scripting languages especially often have their own packaging system and a place where you can look up other programmer's useful code. In Ruby, RubyGems is an excellent resource for this. RubyForge has a huge application archive where you can search for interesting and useful packages. Python uses eggs, or .egg files for packaging. The Python site also has a package index that you may browse.

One great thing you can do to expand your programming horizons is to snoop around in these areas and look at some implementations, and some packages. I guarantee that you will find something sweet, and you will definitely find packages that are extremely useful. So go out there and check out what other people have written. Looking around can save you valuable time when working on projects. Happy hunting...

Monday, April 20, 2009

Regular Geek

This is an excerpt from another blog, I think it has some nice insights:




  • Creation - Some people really enjoy the ability to create something. You start with a blank canvas, or an empty file, and you write code. Eventually that code gets compiled, packaged or whatever and becomes an executable thing. For something like a web site, you actually get to see and interact with your creation.

  • Instant Feedback - Right on the heels of creation is the instant feedback. This is true when you are programming in languages like C++ and Java as well as “really instant” changes like web sites. For programming, you get the code-compile-test cycle giving you the feedback. For web sites, you can change some basic feature and just reload the page in order to see your new results.

  • Puzzles and Problem Solving - Some people, like myself, just love to solve puzzles or various problems. In many cases, this is almost an addiction. These same people probably love to complete puzzles like Sudoku or crosswords. In “modern” terms, you can consider this a “House-complex” (after the fantastic TV show) where solving the problem is the only thing that matters.

  • People - Do you get to meet fascinating people in the software development industry? Yes, absolutely. However, many people get into software development because they do not like people. In product development companies, the programmers can all be “in the back room” and not deal with business people, customers or users. They get their needed (and limited) human interaction by dealing with other programmers.

  • See a Need, Fill a Need - Some people get into programming completely by accident. They may work in drug development research as a scientist, but they need someone to gather data and run complex analysis or simulations. In many cases, there is no funding in the budget for a new hire so that person learns to program. Eventually, they either become too valuable as a programmer or they “fall in love” with software development and they have a new career. This probably happens more often than you think, as there are a lot of programmers who do not have a formal computer science education. This is also good for the industry as it brings a different perspective into development, instead of all the people learning all of the same theories.

  • Money - There are plenty of people who start a career in software development because they want to make a lot of money. In reality, you can make a very good salary in software development, but that can not be the only reason for joining the field. If one of the previous items is not true in your case, you will hate programming within two years. Also, some people see how much money startups can make and figure they just need to learn to program a little to get there. Well, most startups fail to make any money and most programmers do not work at startups.

  • robdiana in Programming, Regular Geek, Mar 2009


For me the 1st and 3rd reasons are it. They are absolutely my bread and butter. Number two just makes life easier. What about you?

Revamping Old Code



remember that program you had to write for your C++ class... Rewriting your old code can be a great way of learning another language. By rewriting something that you already know in a different way, you can quickly pick up new syntax.

This isn't just a great way to learn a new language; It is also a great way to improve your programming skills. Go back and look at some of your old programs. Chances are, you will find ways to improve their implementation, either in speed or amount of code.

For example, I recently took an old piggybank program I had to write in C++ and converted it to Python. All this simple program did was asked for a dollar amount and turned it into the least amount of change. Back when I wrote it for the first time, I used all if statements. While I was re-writing it in Python, I discovered that I could create a better implementation using modulus arithmetic.

Isn't it great how you can learn new material on your old material. Any other suggestions on re-using old code to teach yourself?

Sunday, April 19, 2009

Programming to Program



To learn to program you must program. This is a concept that a lot of time flies over beginners. They get excited about coding, but instead of grinding out some code, they read tutorial after tutorial, or search through the web looking for something that isn't there.

But, once you realize this concept, what do you do about it? It can be pretty tough to think up a program to write yourself. One of the things that I have learned is that often, if you aren't in a class or some environment that forces you to learn, i.e. gives you tasks or assignments, it can be difficult to push yourself.

Probably the best learning tool that can be found on the internet is programming challenges. These appear in books and forums. Someone gives a list of programming quandaries as a challenge to other programmers to solve. These can greatly help you learn to program faster, sharper, and more efficiently.

A great place to find these are forum threads. Right now Programming Forums has some great challenges out there. There is also an e-book that has challenges in it, with robotic judges as well.
These challenges are your best friend, they invite you to program, and even give you what to program. You can't help but learn. Great Stuff!! If you have any sites that you have found, or have made yourself, post them below!

Friday, April 17, 2009

what reversing strings can teach us...



Reversing a string is almost a standard interview question for internships and other jobs requiring programming. What is interesting is that there are many ways to reverse a string, which we will look at below. The answer to which method is the best reveals an interesting lesson in computer science.

Alrighty, so you have your scripting languages that make it mind numbingly easy to reverse a string, in Python the answer is simply mystring[::-1] and voila, string reversed. Probably the most standard way in C++ is to simply make a temp array and iterate through your string, putting each letter from the back to the front in your temp array. This is a satisfactory answer, but it won't win you any brownie points either. The shortest code in C would have to use recursion.

# include

void recurs_string(char * );

/* Definition of the recurs_string() function */

void recurs_string(char *string)
{

if (*string)
{
recurs_string(string+1);
putchar(*string);
}
}

void main(void)
{
char str[100];
printf("\n Input a string: ");
gets(str);
printf("\n Reverse of the string: %s", str);
printf("\n Reverse string is: ");
recurs_string(str);
}

(I got this from here, because I am too lazy to write my own)

While recursion may l
ook impressive, it uses a lot of stack, so it really isn't the best way either. The best way to reverse a string is below.

public string Reverse(string str)
{
// convert the string to char array
char[] charArray = str.ToCharArray();
int len = str.Length - 1;
for (int i = 0; i < len; i++, len--) {
charArray[i] ^= charArray[len];
charArray[len] ^= charArray[i];
charArray[i] ^= charArray[len];
}
return new string(charArray); }
Now if you are
me when you saw this code you were like "what the heck is '^=' ?" that happens to be the XOR (exclusive OR) operator. XOR is a logic operator that returns a one if only one of the two input s is a one. for example 1 XOR 0 = 1, 0 XOR 1 = 1, but 1 XOR 1 = 0. Why this is useful is that XORing two elements three times performs a bitwise switch of those two elements, lets take a look.



1100101
XOR 0111010

= 1011111
XOR 0111010

= 1100101

So you can see, performing XOR operations on two individual characters actually switches there values. This has a practical learning application. Sometimes, the best implementation of a solution can be achieved using low-level logic operations, such as arithmetic shifts, bitwise logic operatiors such as AND, OR, XOR, etc. and binary addition and subtraction. keep this in mind the next time you are trying to optimize your code (and make yourself king of the geeks by writing something that is faster than everybody elses code, and only you can understand.)


Wednesday, April 15, 2009

New to Python (and blogging)

I shall begin at the beginning... I am a Junior in an undergraduate program in Mathematics and Computer Science, I have just gotten a programming internship for the summer. What does this mean? That in the endless sea of knowledge in the programming world I am about two feet deep.

But that's OK. In this blog I will be sharing my new gained knowledge of programming, whatever sundry topics they may be, and ask for opinions and help as well. So, on to my first content.

For this internship I was informed that I will be using Python. I have never used Python seriously before. The closest I have come was dabbling in Ruby, which is pretty sweet, I must say. If anyone out there is looking for good Python resources this is the site. After nosing around on it, I personally recommend Quick and Painless Python Tutorial by Norm Matloff, if you are familiar with other languages, such as C++. Once you have dabbled in Python a little (btw, I am using Context now as my text editor, could I use Eclipse?) Dive into Python might be for you, it tackles some more language specific stuff, that is slightly more advanced. incidently, other than installing the package on python.org's site, I recommend Active Python if you are using Windows, it's free and it allows you to execute your programs on the command line. (Of course all of the above links are to free stuff, I am a college student!)

I will let you know how my Python adventures go, one thing that has intrigued my is Regular Expressions, I haven't looked at them, but from my experience with Ruby, they seem like a must-have. delving more into this later. Also swirling around in my head are questions about GUI's and other tools used with Python, Python in .NET, Iron Python, etc. the list goes on and on, and it seems only hours of scanning the web will satiate my quandaries.

Any useful comments? thoughts? code snippets that might be helpful...