tag:blogger.com,1999:blog-19681622651249581362023-11-16T04:52:10.415-08:00ProgrammingI'm a Computer Science student with a focus in Game Development. Here, I'll talk about my experiences developing software.Unknownnoreply@blogger.comBlogger18125tag:blogger.com,1999:blog-1968162265124958136.post-38438515008571383712010-04-10T22:36:00.000-07:002010-04-11T12:43:02.067-07:00STL AnnoyanceIf you are using the std::vector or std::deque containers and want to obtain an iterator to a location in your container, don't even think about doing this:<br />
<br />
<script src="http://gist.github.com/362512.js?file=badbegin1.cpp">
</script><br />
<br />
Or this:<br />
<br />
<script src="http://gist.github.com/362514.js?file=badbegin2.cpp">
</script><br />
<br />
So, you can't obtain a valid iterator if you try to obtain it before your container has any items. You also can't obtain a valid iterator if you obtain it while your container has an item, but then you add more items to it and try to use the original iterator afterward.<br />
<br />
What gives?<br />
<br />
Calls to insert() (or push_back()) when size() == capacity() will force the container to reallocate its memory (they double in size). A new block of memory is allocated and then the old block is copied to the new block, and the old block deleted. This is bad news if you've obtained an iterator to an item in the old block of memory because it still points there, but the data is no longer there.<br />
<br />
It should be obvious why calls to reserve() have the same effect.<br />
<br />
So, what can you do?<br />
<ul><li>Don't use an iterator obtained prior to a call to insert() or reserve() on your std::vector or std::deque</li>
<li>Keep the iterator updated</li>
</ul>Keeping the iterator updated:<br />
<br />
<script src="http://gist.github.com/362984.js?file=updatingiterator.cpp">
</script><br />
<br />
Note how the address of our iterator never changes, but the address of the item it points to does change. Therein lies the heart of the matter: When these containers reallocate memory, the data gets moved, but nobody tells the iterators to those pieces of data.<br />
<br />
It should also be noted that calls to erase() invalidate any iterators that point to data positioned after the element(s) being erased. The reason should be obvious, as the data is no longer in the same location.<br />
<br />
Moral of the story: Don't use an iterator that was obtained prior to calls on your std::vector or std::deque that will cause them to allocate or deallocate memory. Doing so will invalidate your iterators, and using them will yield undefined behavior, which is a nice way of saying "Garbage data at best, An explosion at worst."<br />
<br />
For a full explanation of when your iterators will be invalidated (there's more situations than I've listed), consult chapter 23 of the <a href="http://www.csci.csusb.edu/dick/c++std/cd2/lib-containers.html">Official C++ Standard</a> (search for all occurrences of the word "valid"):Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1968162265124958136.post-64137855811645765912010-03-29T20:19:00.000-07:002010-04-07T17:50:33.838-07:00Reversing A String - The worse way, The better wayA common programming interview question is to reverse a string. A common first approach is to copy the contents of the string into a temporary string in reverse order, and then copy the temporary string over the original string. Do this in an interview, and you'll be informed that while your solution is correct, it can be much better. Doing it in this fashion is very inefficient, but it is still nonetheless a good place to start. As always, solve the problem first, then optimize. The naive solution would look something like this:<br />
<br />
<script src="http://gist.github.com/359629.js?file=reverse1.cpp"></script><br />
<br />
At this point, the interviewer is going to ask you to perform the reversing "in-place" meaning "do it all in one pass of the string, no double-pass copying shenanigans!"<br />
<br />
So, how do we accomplish this? A basic swap should immediately come to mind. You need to swap pairs of characters in the string as you iterate over it until no more pairs exist. But, how to know when you've reached that point? Sure, you could keep track of indices of the string that have been swapped, but at that point you're diverging toward the inefficiency of the first solution because you'd have to do a lookup in the index table each time you attempted a swap, and that gets slower as your string becomes larger. So, storing indices is out. What else can we do? Well, let's see if there is an algorithm behind this.<br />
<br />
Given the string "abc", what can we deduct about which pairs should be swapped?<br />
<br />
'a' and 'c' get swapped, leaving us with 'b'. Clearly, we see there is nothing else to swap with, but how would we know this internally, from a source code level? The key lies in the positions of the characters in relation to the end of the string. We never want to swap 2 characters unless the location of the second character is > the location of the first character. Using our string "abc", 'a' is located at position 0 and 'c' at position 2. 'b' is located at position 1, but the character at position 2 has already been swapped.<br />
<br />
To compute this mathematically, you do this:<br />
<br />
firstIndex = 0<br />
secondIndex = length of the string - 1<br />
while secondIndex > firstIndex:<br />
swap<br />
increment firstIndex<br />
decrement secondIndex<br />
loop<br />
<br />
Putting this into C, we have the following, efficient reverse algorithm:<br />
<br />
<script src="http://gist.github.com/359630.js?file=reverse2.cpp"></script><br />
<br />
And here is the output, using both versions consecutively on the same string (reverses it, then reverses it again):<br />
<br />
$ ./reverse <br />
original: abc<br />
reverse: cba<br />
reverse2: abc<br />
<br />
Hopefully this has been helpful to you. Remember, the most obvious solution is most likely not the most efficient.Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-1968162265124958136.post-10075682284279738852010-03-27T10:01:00.000-07:002010-04-08T21:55:28.186-07:00When Errors Make Absolutely No Sense......you're probably doing something stupid.<br />
<br />
<br />
I'm working on a new project (C++), and the setup is fairly simple:<br />
<br />
I've got 5 implementation files, a utilities header file, plus my main file. Of those implementation files, 2 of them consist only of utility functions I've previously written.<br />
<br />
In my utilities header, I've got 3 basic structures, plus an enum. 2 of the structures contain 1 very basic function defined within them.<br />
<br />
Now that you have the details, let's get on to the issue...<br />
<br />
I needed to add a function to determine the intersection (if any) between 2 lines in 2d space. Naturally, already having this utils.h file, I decided to throw it in there. I probably shouldn't have, as it is relatively long and complicated enough that the compiler wasn't going to be able to inline it, but at the time I just threw it in there and tried to do a quick compile:<br />
<br />
/tmp/ccnsMHTQ.o: In function `checkIntersection(Point2d&, Point2d&, Point2d&, Point2&)':<br />
VerticalPattern.cpp:(.text+0x2e1): multiple definition of `checkIntersection(Point2d&, Point2d&, Point2d&, Point2d&)'<br />
/tmp/ccqHjPfS.o:HorizontalPattern.cpp:(.text+0x20b): first defined here<br />
<br />
/tmp/cc1AN3z7.o: In function `checkIntersection(Point2d&, Point2d&, Point2d&, Point2d&)':<br />
Enemy.cpp:(.text+0x8e): multiple definition of `checkIntersection(Point2d&, Point2d&, Point2d&, Point2d&)'<br />
/tmp/ccqHjPfS.o:HorizontalPattern.cpp:(.text+0x20b): first defined here<br />
<br />
/tmp/cc6 _16 _11ouOwL.o: In function `checkIntersection(Point2d&, Point2d&, Point2d&, Point2d&)':<br />
main.cpp:(.text+0x1ba): multiple definition of `checkIntersection(Point2d&, Point2d&, Point2d&, Point2d&)'<br />
/tmp/ccqHjPfS.o:HorizontalPattern.cpp:(.text+0x20b): first defined here<br />
<br />
collect2: ld returned 1 exit status<br />
<br />
Huh? That function certainly isn't defined anywhere other than utils.h. So, what gives? My first thought was that I screwed up a header guard somewhere and that coupled with me throwing the definition of the function into the .h file may be causing some issues. So, I checked...<br />
<br />
All header guards were fine. Then I started to wonder if it could be a circular dependency of sorts. But, why then is the newly added function the only one causing the linker error? Wouldn't everything else in utils.h also be causing problems? I decide to conduct a test to find out:<br />
<br />
I added a very simple function definition to utils.h and placed it above the definition of checkIntersection():<br />
<br />
void foo() { int x = 2; }<br />
<br />
A quick re-compile, and...<br />
<br />
I got the same error as before, except now also with respect to foo(). Looking back over utils.h, it becomes clear that the compiler is inlining the functions declared within my structures. This makes sense, because member functions defined inside of a class definition are implicitly inlined. Inlining means that the functions are replaced by inserting the function bodies at the locations in which they are called. This means the linker never sees them, thus has no reason to complain about them in my situation.<br />
<br />
At this point, I have enough information to construct a simple test case to illustrate the issue and better debug it. I need the following setup:<br />
<br />
* A utils.h header file that contains a structure which is composed of a trivial data member as well as a function. <br />
<br />
* Also in that utils.h file, I need to define a free standing function. <br />
<br />
* Lastly, I need to have 2 additional source files, both of which include utils.h, one of which can be the file that holds my main method.<br />
<br />
Once constructed, I'm left with the following:<br />
<br />
<script src="http://gist.github.com/359642.js?file=testcase.cpp"></script><br />
<br />
O.K., time to try to build it and see what we get:<br />
<br />
/tmp/ccwuqYve.o: In function `utilsFoo()':<br />
foo.cpp:(.text+0x0): multiple definition of `utilsFoo()'<br />
<br />
/tmp/ccCIDNQe.o:main.cpp:(.text+0x0): first defined here<br />
collect2: ld returned 1 exit status<br />
<br />
Good. The test case is valid. main.cpp includes both foo.h and utils.h, and foo.h also includes utils.h, thus multiple definitions. Evidently, I'm making a false assumption about what I'm doing, what the header guards are doing, or both... and you know what they say about assuming. Time to stop assuming and starting knowing:<br />
<br />
Header guards only prevent multiple definitions within a single translation unit. Take this situation for example:<br />
<br />
foo.h - includes utils.h, bar.h<br />
bar.h - includes utils.h<br />
<br />
Header guards prevent the contents of utils.h from being included more than once within foo.h (a single translation unit): Once from directly including utils.h, and again when it includes bar.h which in turn includes utils.h.<br />
<br />
So, isn't that what I was doing in my example? No, not at all. I was trying to rely on header guards to prevent multiple translation units from defining the same function. After compilation, main.o and foo.o both contain code for utilsFoo() because both main.cpp and foo.cpp include utils.h, which is where utilsFoo() is defined. It isn't being defined more than once per-file, but rather multiple times across all files (translation units). Thus, the linker has multiple object files that all have code for utilsFoo().<br />
<br />
So, why does sticking the definition of utilsFoo() into an implementation file as opposed to a header file fix the issue? Because in that case, that implementation file is the only object file that has code for utilsFoo(). When other translation units include utils.h, they are simply making the declaration of utilsFoo() visible to themselves. That is to say, they are making themselves aware that the function exists and can be called, but they aren't pulling in the code for the function.<br />
<br />
I feel much better now. Sure, I knew how to fix this from the outset, but it was more important to me to know why I needed to fix it.Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-1968162265124958136.post-49452557061993023052009-07-20T16:44:00.000-07:002009-07-20T17:09:02.631-07:00Getting Over The Initial Excitement HumpSo, you get a new idea for a project. It could be a game, a helpful desktop application, the next big iPhone application, etc... Your brain is working in overdrive with great ideas and you can't wait to start coding. This is normal, and it's great. No better feeling than fleshing out a brand new piece of software that you've come up with.<br /><br />Chances are, you'll hop right into your <span class="blsp-spelling-error" id="SPELLING_ERROR_0">IDE</span> and start fleshing up some quick and dirty code to get the thing off the ground. You're probably too excited to bother with design documents and all of that boring stuff. This is fine to an extent, but before you get too deep into your quick proof of concept, you are going to have to make some formal outlines for your project if it is to be of any modest size.<br /><br />Now that the boring stuff is done, (and unless you are working for a company or making a very large application, you shouldn't have had to spend too much time doing that boring stuff) you can get back to the exciting stuff: programming! At first, things are great. The excitement level is just as high, if not higher than it was at the outset of the idea. But sooner or later, something terrible happens. You lose that excitement and in turn you lose your motivation to work on the project anymore. So, what happened?<br /><br />It is hard to say for certain, but it seems to be human nature, more specifically our tendency to prefer instant gratification, and who can blame us? We just came up with a new killer app, and we want to take the vision in our head and make it come to life. Such is the attraction to this field to begin with: making dreams and ideas into reality using our skills. However, this comes at a price.<br /><br />Once you start getting deeper and deeper into your application, that buzz subsides and you are brought back down to Earth a bit when you have to go through all of the mundane tasks to convert your dream into snippets of source code. Of course, the scope of your project as well as the tools and methods you chose to use to create it will have a huge effect on these mundane tasks (converting between data types, proper design patterns, reusable code, GUI, etc...), but at the heart of the matter it is still the same issue: How do you get back that initial excitement after you drop off to the other side of the hump?<br /><br />I'm not sure I have a good answer for that as I suffer from this situation myself in nearly every project that I start. I find that unless I complete something within a few days, this is almost certain to happen. One issue that plagues me is that I tend to have 3 or 4 of these "killer" ideas floating around at any single time, so once the initial buzz fades during the development of one idea, I go craving my excitement "fix" by starting one of the other ideas, and so the cycle continues. It is an easy trap to fall into for sure.<br /><br />Income could certainly mitigate these effects. Professional developers encounter these same issues, and maybe <span class="blsp-spelling-corrected" id="SPELLING_ERROR_1">more so</span> because they are most likely developing someone <span class="blsp-spelling-error" id="SPELLING_ERROR_2">else's</span> idea, so that initial rush of excitement may never be there. However, it is their job, so they have no choice but to keep plugging away. On the other hand, if you are working on your own personal project in your free time and you have no financial stake in the application's completion, it can be much harder to get out of the rut. Sometimes just wanting that dream realized isn't enough, as I'm sure we've all come to find out all too many times.<br /><br />I think the best solution I've found is balance. Although, there is a very fine line to walk. Initial surges are great, but we must take advantage of them and get as much done in those first few days or weeks as possible. Lay the ground work while your motivation is at its highest. Document your code extremely well, otherwise you'll lose time later trying to figure out what the hell you were doing when you revisit the project. That's where the balance comes in. Take breaks. Work on other projects for a few days, but always keep your main project fresh in your head. Ideally, your side projects should be very small pieces of software. Maybe proofs of concepts or something along those lines. It shouldn't be another full-fledged application. During these breaks though, keep your main project fresh in your head. Look over your source code once a day, revisit your design documents, add <span class="blsp-spelling-error" id="SPELLING_ERROR_3">TODOs</span> to the code if you happen to notice something, but don't add any actual code.<br /><br />I believe these breaks will allow your mind to rest a bit and will prevent you from getting tired of a project. The side projects will keep your skills sharp as well as give you that initial buzz of excitement from working on something new, and hopefully this excitement can carry back over to your main project.<br /><br />If anyone has something that works for them, please share. These are just some things I've found that help me.<br /><br />Cheers.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1968162265124958136.post-74737714694842190322009-07-20T16:35:00.000-07:002009-07-20T16:37:48.459-07:00Curious Observation About EngineeringFor a while, I've wanted to develop a small application that I can use to sync my mp3 player with my computer, or vice versa. It tends to be a fairly common thing, as I'm always adding/removing songs from one or the other. It also comes up a lot if I do a new install of an operating system and I'd like to have some music on there temporarily; it's just easier to transfer it from my mp3 player rather than another file system on a hard drive somewhere.<br /><br />Yesterday, I started thinking about this application again, and today I began fleshing out some things on paper. I was going over things such as how you determine if two files are identical (despite file name, file size, etc... which don't really tell you anything about uniqueness), what sort of sync behavior should be used (mutual-add, mutual-add/delete, etc...), and how to handle the more real-life situation where you've got a number of folders with sub-directories as opposed to just a list of files. I had all of these great ideas of how to solve these problems, and my brain was working overtime for the problems I didn't yet have an answer to. I was looking at source code for some common core UNIX file utilities like diff, cmp, cp, etc... looking for pointers...<br /><br />And then it happened. I realized that I didn't need to make any sort of application. I realized my "problem" was non-existent. Why, you ask?<br /><br />With the use of the built-in UNIX 'cp' command (file copy), and a few command line switches, I could achieve my sync behavior.<br /><br />cp --recursive --update <source> <destination><br /><br />Done.<br /><br />--recursive handles the issue with multiple levels of directories, and --update handles the issue with determining if files are identical or not, as well as handling the mutual-add syncing.<br /><br />The curious part comes in with my reaction to this discovery: I was totally bummed! As an engineer, you tend to <span style="font-weight: bold;">want</span> to have these problems to solve. Then, you are excited once you solve them. However, realizing there was never a problem to solve in the first place doesn't bring that same excitement, it in fact has the opposite effect.<br /><br />It does illustrate a few important concepts of engineering though.<br /><br />1. Don't re-invent the wheel.<br />2. Keep it simple, stupid!<br /><br />Some engineers have a tendency to want to use complex or advanced solutions to problems which don't need them. I myself was bummed that such a simple solution would solve this problem, as I had envisioned a much more "sexy" method. This only leads to trouble down the road, and if at all possible, it's better to realize there's a better way to do something before you've finished doing it the wrong way.Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-1968162265124958136.post-55182696994540720312008-07-09T09:41:00.000-07:002008-07-09T09:50:13.116-07:00Update: Daily ExercisesSo, yesterday was the end of my first full week trying out my new routine of math, programming, and <span class="blsp-spelling-corrected" id="SPELLING_ERROR_0">guitar</span> each day. I felt it was a good introductory week to help me get used to the effort and time required to do such a thing, and I learned a lot about what changes I'll need to make in order to be successful with this process.<br /><br />I stuck to my plan about 4 days out of the 7. It was a bit of a bad week to start this, as it fell over a holiday weekend, and 2 of the days in the 7 I had softball games (one of which I was injured in). Nonetheless, it was simply an introduction into what it would be like, and successful in that regard.<br /><br />My guitar playing has improved dramatically. Not to say that I was bad, but I'm able to play some things now after only 7 days than I really ever imagined I'd be able to. As for programming, I found myself solving some complex problems of which recently I found rather stubborn. The Math was probably the hardest thing to sit down and do, and I failed in this department more than any other. However, when I did sit down and work some problems, each day they became easier.<br /><br />I guess the main things I learned are:<br /><ul><li>It's hard work to do a routine like this with 3 different things. Usually people have a focus on one thing, and that's easy.</li><li>Tracking progress is essential. I didn't do any sort of that this past week and I don't feel like I can measure what I've accomplished in much of a concrete way. With guitar it's easier because I can set a goal to learn a song or a part of a song, and then do it. The other areas will require some structure.</li><li>It works.</li></ul>I'll update this again at some point, at the longest I'll wait until a full month, but I may update it before then. I encourage you to try this out, whether it's with 1 thing, 3 things, or as many as you think you can handle, although I wouldn't push it much past 3 or the point of diminishing returns will surely kick in unless you don't have any other daily responsibilities. I work 2 jobs, so it's a time management exercise as well to fit all this stuff in!<br /><br />Good luck.Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-1968162265124958136.post-10651785595243419052008-07-01T07:56:00.001-07:002008-07-01T08:04:48.486-07:00Something has to changeThis encompasses more than just programming, but it's the best place for it to go and I didn't feel like creating a new blog section...<br /><br />I have been pretty busy lately, or that is to say "I've always got a lot to do, but usually don't accomplish what I should due to lack of structure and being worn out."<br /><br />So, in that light, I came up with a plan to improve my skills in the areas of which I require them: Programming, Math, and Music.<br /><br />Every day I will do the following:<br /><ul><li>Write code - I tend to do this anyways, but it's easy to do a lot of work for a 3 days and then take a day off. Nope, not anymore.</li><li>Do Math - I'm not great at Math, but my shortcoming in it is only due to lack of general effort toward the subject. Each day I will work some Math problems, as I need to be ready for a placement test anyways, I also need to sharpen my skills and keep them sharp for my future career.</li><li>Practice guitar - Practicing guitar is one of the most horrible things ever. Note I said "practice" and not "play". It's hard to force yourself to do exercises, but unless you do, you get into a rut and you never progress.</li></ul>After one week of doing this, I'll post an update and let you know how it's worked out. All 3 of these areas are very closely related in terms of brain function, so while only doing one of them each day would greatly improve that area, doing all 3 should have a greater effect. The idea behind this is that you can't simply work on these things for 8 hours in one day, and then not do anything for the next 3. It's about the constant <span class="blsp-spelling-corrected" id="SPELLING_ERROR_0">repetition</span> of the activity day after day that will bring results. It improves memory, coordination, muscle memory, etc... I'll also make it a point to sit down and read something (other than e-mail...) each day. I don't particularly need help in this area, but reading often improves coordination (line skipping and such), concentration, vocabulary, and all sorts of other things worthy of improving.<br /><br />I think not only will this routine improve the areas of which I'm targeting, but that it will also improve my overall productivity in life as I'll be on a more driven and focused path throughout my day, and I'll be more inclined to get something done rather than just chill out.<br /><br />Until next time...Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-1968162265124958136.post-47957978878055428852008-06-06T16:37:00.000-07:002008-12-09T09:15:14.191-08:0010 Great Features In Netbeans IDE 6.1Netbeans is an excellent IDE from Sun Microsystems. It is written in Java and runs on all major platforms. With the latest 6.1 release, Netbeans has really stepped up its game and can now compete with some of the market leaders for integrated development environments. For more information about Netbeans, visit <a href="http://www.netbeans.org">http://www.netbeans.org</a><br /><br />Below is a list of 10 really helpful (...and cool) features in Netbeans 6.1. My examples are illustrated using a C++ project, but almost all of them apply across the board to the other languages that Netbeans 6.1 supports: <a href="http://www.netbeans.org/features/index.html">http://www.netbeans.org/features/index.html</a><br /><br /><br />1. <span style="font-weight: bold;">Code Bookmarks</span> - This feature allows you to bookmark individual lines of code for easy browsing later.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXwS19h4voxIUrYT8TSJ4dQea7DGn2kTML1vBLgPNaJDSfh7EHFMvrhZy9JwW0JHjYqp0DLF0B6tVXGLRNnvrO-mqGwNpFNwIf6o308Y7xVy4jFypI_aGAdgH-iL0RhpMMV9JMhAeU7V8/s1600-h/bookmark.png"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXwS19h4voxIUrYT8TSJ4dQea7DGn2kTML1vBLgPNaJDSfh7EHFMvrhZy9JwW0JHjYqp0DLF0B6tVXGLRNnvrO-mqGwNpFNwIf6o308Y7xVy4jFypI_aGAdgH-iL0RhpMMV9JMhAeU7V8/s320/bookmark.png" alt="" id="BLOGGER_PHOTO_ID_5208919030565952482" border="0" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9zda5w-mwvhyVatIgYglqAy5qCIe8oWiKKrjaZ3Lt_o_zsnc8-5qVh2n9yZYiLdXcCD8t4Ufur3zeQP7VGxk9RlDc0yShCsAhyphenhyphenOdgLx33DcWHSOJPL9wWXl4br3oXx9L9rQtVDqveQe0/s1600-h/bookmark2.png"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9zda5w-mwvhyVatIgYglqAy5qCIe8oWiKKrjaZ3Lt_o_zsnc8-5qVh2n9yZYiLdXcCD8t4Ufur3zeQP7VGxk9RlDc0yShCsAhyphenhyphenOdgLx33DcWHSOJPL9wWXl4br3oXx9L9rQtVDqveQe0/s320/bookmark2.png" alt="" id="BLOGGER_PHOTO_ID_5208919216157397858" border="0" /></a><br /><br /><br />2. <span style="font-weight: bold;">Build Platform</span> - When working with a C/C++ project, you can select which platform you'd like to build the executable for.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWMWA3VKVIeGPPe-EZhZ1HGqfs072bgkEk2GVYlvUS3HYzzmiiqnnR3lYl1scH4QTeUVeABMTZW94ScXBs0Lg0f9eminOrBnWISQe8e_6YBAfhp6BbQA-N12PCcx3l3wt8w2BtgqAk5Kk/s1600-h/build.png"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWMWA3VKVIeGPPe-EZhZ1HGqfs072bgkEk2GVYlvUS3HYzzmiiqnnR3lYl1scH4QTeUVeABMTZW94ScXBs0Lg0f9eminOrBnWISQe8e_6YBAfhp6BbQA-N12PCcx3l3wt8w2BtgqAk5Kk/s320/build.png" alt="" id="BLOGGER_PHOTO_ID_5208920830507335394" border="0" /></a><br /><br /><br />3. <span style="font-weight: bold;">Code Completion</span> - If you've used Visual Studio, then you've seen this type of thing before. While coding, you can pause (or use Ctrl+Space) and a code completion dialog will pop-up. This works for standard library items as well as items specific to user-created classes.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMFuMjX_35qk_7OPaOfwGPWAj47LDo3Y4YgaMd9jaeJJ7XLRxu00MDO1ElPKNH2e_4qJwuxhMLJxtYTAD8TR93mzWJrE92xfmhnAeJVIo_hpOM_MBjNojG6D_4pvjzgNZuXwrzULnNNQc/s1600-h/code-complete.png"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMFuMjX_35qk_7OPaOfwGPWAj47LDo3Y4YgaMd9jaeJJ7XLRxu00MDO1ElPKNH2e_4qJwuxhMLJxtYTAD8TR93mzWJrE92xfmhnAeJVIo_hpOM_MBjNojG6D_4pvjzgNZuXwrzULnNNQc/s320/code-complete.png" alt="" id="BLOGGER_PHOTO_ID_5208923417768780386" border="0" /></a><br /><br /><br />4. <span style="font-weight: bold;">Code Formatting</span> - Netbeans 6.1 gives you the ability to customize every possible code formatting option you can think of. Each case is separated into a group, and then each item in that group is a check-box. Changes are reflected in real-time via a preview pane to the right which is populated with example code. Once you make changes to these settings, Netbeans automatically accounts for them while you're coding. Very cool.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJ3L2xOlfCl9p7IzGF78igbMP6ZQsenmFVtr0no8abdGEekTRQhfegaYyc2GbcttDFpqoNDy_MCJ-38MSwt0YDCsQ7LUqa5K8lPdeKqABu70-PaCcKe9Kavit4ncFcbEvris-RTOMn3h0/s1600-h/code-format.png"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJ3L2xOlfCl9p7IzGF78igbMP6ZQsenmFVtr0no8abdGEekTRQhfegaYyc2GbcttDFpqoNDy_MCJ-38MSwt0YDCsQ7LUqa5K8lPdeKqABu70-PaCcKe9Kavit4ncFcbEvris-RTOMn3h0/s320/code-format.png" alt="" id="BLOGGER_PHOTO_ID_5208923689923628354" border="0" /></a><br /><br /><br />5. <span style="font-weight: bold;">Single File Compile </span>- Tired of building your entire project when all you want to do is make sure that the file you've just changed compiles cleanly? Netbeans 6.1 offers the "Compile File" option to do just that.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb-7izL60geZjx6MLHVuZ7L-kaiDOOYJkCBnbmSrZ6rlOoQN2sr3XCQbg5bB0U1hmTR7g9-keD2VPI_dkJaLajdH14ebK9AtiRyAr4eVBxpbeJdfk8QlNZvUPs6gO5cpxCrUioXXMMPqo/s1600-h/compile-file.png"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb-7izL60geZjx6MLHVuZ7L-kaiDOOYJkCBnbmSrZ6rlOoQN2sr3XCQbg5bB0U1hmTR7g9-keD2VPI_dkJaLajdH14ebK9AtiRyAr4eVBxpbeJdfk8QlNZvUPs6gO5cpxCrUioXXMMPqo/s320/compile-file.png" alt="" id="BLOGGER_PHOTO_ID_5208923747571598050" border="0" /></a><br /><br /><br />6. <span style="font-weight: bold;">Diff</span> - Diff is a very powerful tool for tracking changes between 2 different versions of a file. It isn't source control, it's simply a tool to contrast 2 versions of the same file, and it's commonly used when writing software patches. Netbeans 6.1 gives you the ability to run a Diff on a file right inside of the IDE.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbprVTjXwNDlFHRL_FTDoo90reg2PoS8E4jpZqLvzFOCtgDV9oodj11KQtlzX9FRNFMu5TQvHawAdN_kTeJvQV0coyTgDg6a6OI0ZGgEZeWFmx5yzTIhUR4yQBjsPSCoquKNvqEYikHnk/s1600-h/diff.png"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbprVTjXwNDlFHRL_FTDoo90reg2PoS8E4jpZqLvzFOCtgDV9oodj11KQtlzX9FRNFMu5TQvHawAdN_kTeJvQV0coyTgDg6a6OI0ZGgEZeWFmx5yzTIhUR4yQBjsPSCoquKNvqEYikHnk/s320/diff.png" alt="" id="BLOGGER_PHOTO_ID_5208924076891170306" border="0" /></a><br /><br /><br />7. <span style="font-weight: bold;">Favorites</span> - Netbeans 6.1 allows you to add files from your project to a list of Favorites. This is extremely helpful in large code bases.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfGISpj_Iv0e4d4a8x8PaG1Us2shc0mXJU3L4VnhaSK6UE4Mvp8LjaVlT4RUVzJ0AlYAANC2dl1nwIf6gAjdOenoy1cu6ObOtg2AUo8DLd4mdLM9xkuGoBgeFobFZiHYRC0bQT7-kA66A/s1600-h/favorites.png"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfGISpj_Iv0e4d4a8x8PaG1Us2shc0mXJU3L4VnhaSK6UE4Mvp8LjaVlT4RUVzJ0AlYAANC2dl1nwIf6gAjdOenoy1cu6ObOtg2AUo8DLd4mdLM9xkuGoBgeFobFZiHYRC0bQT7-kA66A/s320/favorites.png" alt="" id="BLOGGER_PHOTO_ID_5208924091261257922" border="0" /></a><br /><br /><br />8. <span style="font-weight: bold;">Symbol Tracking</span> - While viewing a source file, simply right-click on a symbol and you have the option to track various things such as the definition/declaration of the symbol, its source/header file, all occurrences of the symbol in the current file/entire project, and more. Again, very helpful in large code bases.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLahXZItO1TpNWj_utxIIyqmPiIHC9m82dfyJTtAVgpCsVBrCvDr5Qf8GPIiD96BmLqrqzzl3HKB1yO8T44fRg2o3XI9Wh-24KJz96Oye58GQKkCxFcoDTgHITfxiLjNw-_23J6cxokc8/s1600-h/find-occurances.png"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLahXZItO1TpNWj_utxIIyqmPiIHC9m82dfyJTtAVgpCsVBrCvDr5Qf8GPIiD96BmLqrqzzl3HKB1yO8T44fRg2o3XI9Wh-24KJz96Oye58GQKkCxFcoDTgHITfxiLjNw-_23J6cxokc8/s320/find-occurances.png" alt="" id="BLOGGER_PHOTO_ID_5208924099296941426" border="0" /></a><br /><br /><br />9. <span style="font-weight: bold;">Include Directories</span> - When developing a C/C++ project, Netbeans 6.1 makes it easy to add additional include directories to it's search path.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEha-Yz6DL0Qz6GW_5bXwG4MuJEnTQmmxB4pr6Jm_4clP793WY7udxs5bgRDDgc8hpM1iWzJyanCqC5WqGo48FlVPunKtRAL6lUAa0vCV3tGgcIFWM0whK5BO4S_rI9aAKYrzDcRukgG8LE/s1600-h/include.png"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEha-Yz6DL0Qz6GW_5bXwG4MuJEnTQmmxB4pr6Jm_4clP793WY7udxs5bgRDDgc8hpM1iWzJyanCqC5WqGo48FlVPunKtRAL6lUAa0vCV3tGgcIFWM0whK5BO4S_rI9aAKYrzDcRukgG8LE/s320/include.png" alt="" id="BLOGGER_PHOTO_ID_5208924102613645602" border="0" /></a><br /><br /><br />10. <span style="font-weight: bold;">Local History</span> - This is one of the coolest features I've seen in a while. Just think source control, except it's stored internally and it's graphical.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO9AaR3MkNVi3tA3okGvjjB4Xsw7UG9C5B8PVvpV5azFbO02kdxomjJ3VSScVmZZhcPxbXuFq3vxZqeFE7zWccrwXdDQTSVFZfpsjgRVN9VtDUlMV9_Yl9f1mmU9pseT4yXxI_dgabes4/s1600-h/local-history.png"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiO9AaR3MkNVi3tA3okGvjjB4Xsw7UG9C5B8PVvpV5azFbO02kdxomjJ3VSScVmZZhcPxbXuFq3vxZqeFE7zWccrwXdDQTSVFZfpsjgRVN9VtDUlMV9_Yl9f1mmU9pseT4yXxI_dgabes4/s320/local-history.png" alt="" id="BLOGGER_PHOTO_ID_5208924108463328066" border="0" /></a><br /><br /><br />Hopefully this list has gotten you excited about Netbeans 6.1. If not, read it again! :)<br /><br />This review was submitted for the Sun Microsystems Student Reviews Contest. You can get more information about this contest here: <a href="http://www.sun.com/products-n-solutions/reviews/studentzone/contest.jsp">http://www.sun.com/products-n-solutions/reviews/studentzone/contest.jsp</a>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-1968162265124958136.post-22325305352681091892008-04-18T20:50:00.000-07:002014-08-06T06:04:34.455-07:00Netbeans: Why It MattersThe topic comes up all the time: "Which <span class="blsp-spelling-error" id="SPELLING_ERROR_0">IDE</span> to you use?"<br />
<br />
It doesn't matter which programming language is being discussed or the scope of the project, developers always want to know what the "other guy" is using. I tend to do all of my development in C/C++ and it probably comes as no surprise to others using <span class="blsp-spelling-error" id="SPELLING_ERROR_1">Netbeans for C/C++</span> the shock and resistance I receive when I tell people this.<br />
<br />
I'm a Linux guy. Up until last year, I had never written a lick of code under any platform other than Linux. When I was eventually "forced" to write some C++ under Windows, I felt like a foreign exchange student with no sponsor. I had absolutely no idea what was going on. I almost started to believe I didn't know how to program anymore. Where was <span class="blsp-spelling-error" id="SPELLING_ERROR_4">gcc</span>? How do I run this thing? How in the hell do I use Visual Studio? In walks <span class="blsp-spelling-error" id="SPELLING_ERROR_5">Netbeans</span>, the one thing I can always count on in my software development. That is, aside from the knowledge I've already garnered.<br />
<br />
The fact that <span class="blsp-spelling-error" id="SPELLING_ERROR_6">Netbeans</span> offers a full-fledged <span class="blsp-spelling-error" id="SPELLING_ERROR_7">IDE</span> that runs on multiple platforms is enough in itself. The fact that it has support for every language you could ever want (or need) to write code in is nearly unprecedented. The fact that it does all of this better than any <span class="blsp-spelling-error" id="SPELLING_ERROR_8">IDE</span> I've ever seen is teetering on goofy. The fact that it's open source is down right nuts.<br />
<br />
I, like many developers, am forced to write code in a number of different languages for a number of different platforms. It's frustrating enough having to <span class="blsp-spelling-corrected" id="SPELLING_ERROR_9">remember</span> the nuances of all of these different languages. You do something one way in Java, another in C++, a new way in Ruby... but that's not the worst part. Chances are, unless you are really just using an editor as opposed to an <span class="blsp-spelling-error" id="SPELLING_ERROR_10">IDE</span>, you have to write this code with a different development tool. Isn't the idea behind an <span class="blsp-spelling-error" id="SPELLING_ERROR_11">IDE</span> to make the whole development process easier? What's easy about juggling different programming languages along with different development environments? In walks <span class="blsp-spelling-error" id="SPELLING_ERROR_12">Netbeans</span>.<br />
<br />
<span class="blsp-spelling-error" id="SPELLING_ERROR_13">Netbeans</span> provides developers with a consistent look and feel across all of its supported languages. This allows developers to use <span class="blsp-spelling-error" id="SPELLING_ERROR_14">Netbeans</span> for all of their tasks without missing a beat. There is no learning curve. If you've written Java code in <span class="blsp-spelling-error" id="SPELLING_ERROR_15">Netbeans</span>, congratulations, you can now use <span class="blsp-spelling-error" id="SPELLING_ERROR_16">Netbeans</span> to develop software in any other language. I think people overlook the benefits of this, mainly because it's not a very common <span class="blsp-spelling-corrected" id="SPELLING_ERROR_17">luxury</span>. The old school of thought between developers, namely C/C++ developers, is that you use a text editor on Linux, and Visual Studio on Windows. For a lot of people, that's a deal breaker. I can't say I blame them: Visual Studio is usually a nightmare to use for anyone coming from the purist environment that is Linux/UNIX C/C++ development. In walks <span class="blsp-spelling-error" id="SPELLING_ERROR_18">Netbeans</span>. You're a Linux C/C++ developer coming over to Windows for a project? No sweat, just install <span class="blsp-spelling-error" id="SPELLING_ERROR_19">Netbeans</span>, install the C/C++ development tools (compiler, make system, etc...), and get right back to work. The effect this has on productivity is astounding. Not only can you get right to work, but all the experience you gain while working on this project under Windows can be directly translated back to Linux, or whatever your native environment is because the <span class="blsp-spelling-error" id="SPELLING_ERROR_20">IDE's</span> interface is the same, because the <span class="blsp-spelling-error" id="SPELLING_ERROR_21">IDE</span> is the same!<br />
<br />
I talk a lot about C/C++. Guilty. Every other language is on a "need to use" basis with me. However, I've done a lot of work in Java, some work in Ruby, and recently my first ever experience with JavaScript. Let's focus on JavaScript since that's a pretty old school language. The JavaScript project I was working on involved some proprietary Microsoft technologies. Given that, I was basically forced to use Visual Studio. Luckily the new version isn't so bad, but I still wasn't pleased. I was out of my element, and I had to worry about more than just the code I was writing. That's a bad thing. In walks <span class="blsp-spelling-error" id="SPELLING_ERROR_22">Netbeans</span>. In the 6.1 Beta, JavaScript support was added. <span class="blsp-spelling-error" id="SPELLING_ERROR_23">Eurkea</span>! I said. The nature of the project was such that I could write the JavaScript code separate from those other <span class="blsp-spelling-corrected" id="SPELLING_ERROR_24">proprietary</span> technologies I mentioned, so I installed the beta and got to work. Not only was the learning curve involved with Visual Studio cut out of the mix, but the fact that I had the reference documentation built in to <span class="blsp-spelling-error" id="SPELLING_ERROR_25">Netbeans</span> was instrumental in my rapid development iterations with this project having never written any JavaScript in my life!<br />
<br />
The <span class="blsp-spelling-error" id="SPELLING_ERROR_26">IDE</span> war will never be settled. Maybe that's for the best, to each his own. However, the bottom line is <span class="blsp-spelling-error" id="SPELLING_ERROR_27">Netbeans</span> makes you a better developer. It helps you do your job, and it helps you do your job well. The fact that it covers the major elements of all of the languages it supports is second to none. Break your code down by classes? Done. Attach an in-depth <span class="blsp-spelling-error" id="SPELLING_ERROR_28">profiler</span>? Cake. Debugger? You betcha'. Source control? Look ma', no hands.<br />
<br />
If you've never tried <span class="blsp-spelling-error" id="SPELLING_ERROR_29">Netbeans</span>, I strongly encourage you to do so. It's alright, you don't have to tell anyone that you're using <span class="blsp-spelling-error" id="SPELLING_ERROR_30">Netbeans</span>. You can lock yourself away, keep all the lights off, cover your face if you must, but just try it. Once you put all the hype aside, you'll realize just how invaluable a tool like <span class="blsp-spelling-error" id="SPELLING_ERROR_31">Netbeans</span> is. And then you'll wonder why you weren't using it years ago.<br />
<br />
--<br />
<br />
This blog entry was submitted for the Netbeans 6.1 Beta Blogging Contest. For more entries, check out the contest page here: <a href="http://www.netbeans.org/competition/blog-contest.html">http://www.netbeans.org/competition/blog-contest.html</a>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-1968162265124958136.post-1935152555573037232008-03-14T12:40:00.001-07:002008-03-14T12:54:34.885-07:00All I need to know I learned in... the library?I was fortunate enough to attend a school for a year that had an <span style="font-style: italic;">amazing</span> library. Not just for computer science, but for everything, from what I've heard. Clearly, since I'm a software guy, I only cared about their collection of computer science books, and they certainly didn't disappoint.<br /><br />If you could find it on <span class="blsp-spelling-error" id="SPELLING_ERROR_0">O'reilly</span>, you could find it in this library. After I went there for the first time, I was hooked. Never in my life had I viewed going to the library as an exciting experience. I <span style="font-style: italic;">wanted</span> to go to the library. I'd spend 90 minutes browsing the shelves.<br /><br />Then, for reasons we won't go into, I transferred schools. I ended up at a pretty decent community college for a year while I was transitioning, and I was deeply saddened by what I found in that library. So, what's my point?<br /><br /><span style="font-weight: bold;">Those books are there for a reason, and they are <span style="font-style: italic;">free</span>. Take advantage of them.<br /><br /></span>Computer science is one of only about a handful of professions that is pretty "take-home". Maybe that isn't true for everyone, but the vast majority of people in this line of work, namely programming, take their work home with them. It's not necessarily because they are work-a-<span class="blsp-spelling-error" id="SPELLING_ERROR_1">holics</span>, but simply because they <span style="font-style: italic;">love</span> doing what they do. Their brains don't allow them to just "turn it off" and leave some programming issue for the office. They <span style="font-style: italic;">enjoy</span> solving problems. Unfortunately, sometimes people's jobs depend on them taking their work home with them, but we won't get into that. In fact, this paragraph needs to be it's own entry, so I digress...<br /><br />Basically what I'm saying is that you can't be the best programmer that you'd like to be by relying on your college courses to teach you what you need to know. I may not be done with school yet, but I'm not exactly naive on this matter. Your college classes teach you very little about what being a programmer means. In part, it's not their fault. They have to keep things at a general level to allow for a vast number of technologies that the students may have to work with. Still though, you have got to put in the work outside the class room. I don't think I need to belabor this point too much as if you've made it through at least 2.5 years of a CS/SE degree, you truly do love what you are doing. Also though, you will be expected to continue to learn when you graduate. You'll have to use a language at work that you may hate, or may not know at all. <span class="blsp-spelling-error" id="SPELLING_ERROR_2">You'l</span> have to learn <span class="blsp-spelling-error" id="SPELLING_ERROR_3">API's</span> you've never even heard of, etc... but you can't give that as an excuse to your boss. There will be some degree of toleration for your lack of experience in a particular area, of course, but when it comes down to it, if you want to keep your job and do well at it (which in-turn means you'll enjoy it a hell of a lot more), you've got to put some effort in "off the clock". I'm not saying you have to ssh in, <span class="blsp-spelling-error" id="SPELLING_ERROR_4">vnc</span>, whatever...and start writing your work code from home, but you will have to crack a book (or 5 as I find myself doing) and soak up some knowledge.<br /><br />Take advantage of your schools library instead of taking it for granted. You'll be surprised how much you enjoy reading. Not a bad place to meet girls either, especially when you are carrying around fancy sounding programming books...<br /><span style="font-weight: bold;"><span style="font-weight: bold;"><br /><br /></span></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1968162265124958136.post-55244447813264295892008-03-14T11:33:00.000-07:002008-03-14T13:09:41.060-07:00There's more to coding than...well.... coding.Learning how to write software is really a tiny piece of what it means to be a programmer. Let's be honest, writing code is actually pretty easy to do. You spend a few years learning how the basic logic structures work, the looping, function calls, return values, blah blah blah. After that, the most work you put in is studying some new <span class="blsp-spelling-error" id="SPELLING_ERROR_0">API</span> or learning the nuances of some new language. All in all though, it's not terribly hard to do.<br /><br />Unfortunately, there's a lot more to it than that. The book series "<span style="font-style: italic;">Effective C++</span>" by Scott Meyers (I've provided links at the end of this entry to all of the items I rave about, so no need to fire up Google) really opened me up to this notion. It was the first book I had read about programming that didn't teach you how to write code, but how to write <span style="font-style: italic;">proper </span>code<span style="font-style: italic;">. </span>Actually, not just proper code<span style="font-style: italic;">, </span>but<span style="font-style: italic;"> great <span style="font-style: italic;">code. </span></span><span>It was such a breath of fresh air to pick up a book about programming and not have to see the same step-by-step teaching process. Books like this (you should have already gone and checked it out from your library by now...if not, stop reading and go. now. I'm waiting.) focus on things that too many programmers neglect: writing proper, efficient code that does exactly what you intend it to do, and does so very nicely.</span><span style="font-style: italic;"><span style="font-style: italic;"><br /></span></span><br />But again, that's just another piece of the puzzle. I've been browsing some programming blogs recently and I came across this one: <a href="http://www.gamesfromwithin.com/">http://www.gamesfromwithin.com/</a> There is some really great content in there and I encourage you to check it out. The <span class="blsp-spelling-corrected" id="SPELLING_ERROR_1">relevance</span> for this discussion is that the author is a big proponent of agile development and test driven development. If you aren't familiar with those concepts, I hear Google works quite well. The basic run down of agile development is that it's a production mechanism of sorts that stresses quick iteration of software based on client feedback (whether the clients are other programmers working on other features or your actual end-users depending on the type of project you have). A main element of agile development tends to be a team oriented approach that involves things like <span class="blsp-spelling-error" id="SPELLING_ERROR_2">XP</span> (2 programmers working side-by-side on the same piece of code).<br /><br />For an example of how well these things can work, check out this entry in the above mentioned blog: <a href="http://www.gamesfromwithin.com/articles/0602/000104.html">http://www.gamesfromwithin.com/articles/0602/000104.html</a> You'll be amazed at how much work gets accomplished with this method.<br /><br />Test driven development follows with the iterative theme in that you essentially reverse the coding process. How? With the use of a unit testing framework, you write your tests <span style="font-style: italic;">before</span> you write your code. Clearly, the test should fail. Then, you write just enough code to make that simple test pass. The key word there is simple. The tests you design should be very small and simple to implement. The author of that blog suggests between 1-2 minutes to design the test, and not much more than 15 to implement the code to pass the test. "<span style="font-style: italic;">Test Driven Development</span>" by Kent Beck seems to be a godsend book on this design methodology. I just picked it up from the library yesterday and it's very helpful in outlining the process, go get it!<br /><br />These are just 2 examples of design methodologies in software engineering, but there are a ton of other ones. Some work better for certain things, but the point is that this stuff matters. It's vital in a professional software development environment. Without things like this, nothing would get done, and even if it did, the result would be awful. I encourage you to start learning about this stuff while you are still in school, because chances are you won't have too much meaningful class time devoted to things like this. All of it can only serve to make you a better programmer.<br /><br />This is where the distinction between "Computer Science" and "Software Engineering" comes in. Software engineering is devoted to stuff like this. It's all about the design, the planning, the process. Computer science tends to be focused on the implementation alone. The curriculum in colleges today leaves much to be desired in my book. How can you send CS majors out into the work field with very little knowledge of software engineering principals? To me, they go hand in hand. You can't write any sort of decent code without a design or a planning process. What about a <span class="blsp-spelling-error" id="SPELLING_ERROR_3">roadmap</span> or schedule for the project? You can't just "wing it" and expect any worthwhile results to come out the other end. Some people think all of this "management" should be the responsibility of the projects "manager". Maybe so, but I don't think it's black and white. The project manager can't write your test cases for you. The project manager (in the sense that most people think of him/her in) can't set realistic and useful code milestones for you. As a programmer, you can't get to where you need/want to be unless you <span style="font-style: italic;">know</span> where that place is before you start.<br /><br />I encourage you to read as many blogs by professional developers as you can. These people are wise beyond my years, so I could go on and on, but you're better off hearing it out of their mouths (or fingers...) than having me repeat to you what I've learned from them. The "Games From Within" blog above is really outstanding. I learned more about software engineering in a few hours than I have in 3 years of college. In addition, look for some language-specific blogs by some seasoned vets as well. These blogs tend to focus on many similar topics that the "Effective C++" series does. That is to say, the "how to do it right" as opposed to just the "how to do it". I found this site the other day and it has a wealth of information from blogs by over a dozen different professionals, to regular articles: <a href="http://www.artima.com/index.jsp">http://www.artima.com/index.jsp</a><br /><br />Good luck, and remember: learning how to program is just the first small step in being a software developer.<br /><br /><span style="font-weight: bold;">Resources You Need To Check Out</span><br /><br /><span style="font-weight: bold;">Websites / <span class="blsp-spelling-error" id="SPELLING_ERROR_4">Weblogs</span></span><br /><ul><li><a href="http://www.artima.com/index.jsp">http://www.artima.com/index.jsp<br /></a></li><li><a href="http://www.gamesfromwithin.com/">http://www.gamesfromwithin.com/</a></li><li><a href="http://powerof2games.com/">http://powerof2games.com/</a></li><li><a href="http://www.aristeia.com/">http://www.aristeia.com/</a></li></ul><span style="font-weight: bold;">Books</span><br /><ul><li><a href="http://www.amazon.com/Test-Driven-Development-Addison-Wesley-Signature/dp/0321146530">http://www.amazon.com/Test-Driven-Development-Addison-Wesley-Signature/dp/0321146530</a></li><li><a href="http://www.amazon.com/Effective-C%2B%2B-Addison-Wesley-Professional-Computing/dp/0321334876/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1205521782&sr=1-1">http://www.amazon.com/Effective-C%2B%2B-Addison-Wesley-Professional-Computing/dp/0321334876/ref=pd_bbs_sr_1?ie=UTF8&s=books&<span class="blsp-spelling-error" id="SPELLING_ERROR_5">qid</span>=1205521782&<span class="blsp-spelling-error" id="SPELLING_ERROR_6">sr</span>=1-1</a></li></ul>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1968162265124958136.post-73263173298691614872008-03-10T21:13:00.000-07:002008-03-10T21:32:07.253-07:00There's room for everyoneOne of my biggest problems to date has been that I get discouraged when I look at what's already been accomplished in this field. When you are sitting down to work on a trivial idea you've come up with, it's easy to stop and say "Wow, do you have any idea how complex the <span class="blsp-spelling-error" id="SPELLING_ERROR_0">GCC</span> compiler is? What the hell am I doing with this simple program?!" It's an easy trap to fall into, but a deadly one.<br /><br />We can't all be John <span class="blsp-spelling-error" id="SPELLING_ERROR_1">Carmack</span>, Bill Gates, Linus Torvalds, etc etc etc... but that doesn't mean we should find a new profession. Implementing those trivial ideas are essential for growing as a developer, and if you don't go through that process you'll never get to where you want to be. John <span class="blsp-spelling-error" id="SPELLING_ERROR_2">Carmack</span> didn't roll out of bed one day and write a 3D game engine. He had years of programming experience. Granted, he's a very intelligent man when it comes to math and science, regardless of his programming abilities, but again, he's one of the many exceptions. Most people simply aren't that gifted. However, if programming is the field you want to be in, you can work hard enough at any area of it and become proficient.<br /><br />The only remedy I've found for this issue is that when you have an idea for a piece of software you'd like to create, don't "Google it". Most ideas that most of us have will be based off of some piece of software that is already in use. Going to Google to check out some of those applications is only going to worsen this issue. I like to get off of my computer, grab a pen and paper and start designing the system "offline". It's actually a lot more productive than sitting in front of your monitor, and you can't get discouraged if you pretend that nobody has ever made this piece of software before.<br /><br />Going back to the trivial nature of some of the programs we may write... Just as programming books start you off simple before branching into pointers, objects, templates, data structures, etc... you should be doing that with your code. Now, this tends to happen naturally anyways since you can't well write code involving things you don't yet know how to do, but I know I've certainly tried. Not to say that it's <span style="font-style: italic;">always</span> a bad thing to test new waters, but you shouldn't really make a habit of doing something until you understand it. A book progresses rather quickly, but your projects should progress much more slowly in terms of the complexity of the underlying software. This is paralleled by the fact that you cannot simply read a programming book front to back as if it were a novel, it must be an interactive experience in which you are typing the code from the book, doing the examples, doing the projects, etc... The more time you spend building the complexity of your projects up, the better off you'll be in the long run because you'll have an expert-level understanding of everything you've done, which will then make the transition into the really advanced stuff easier.<br /><br />A great way to do this is to develop your software idea just like a mainstream piece of software. Have iterative releases of your application, adding new features and <span class="blsp-spelling-error" id="SPELLING_ERROR_3">refactoring</span> code along the way. Make a habit of creating a "<span class="blsp-spelling-error" id="SPELLING_ERROR_4">TODO</span>" list after each release so that you have specific points to focus on. Ideally you'd have setup some sort of road map at the outset of the project, so you should already have some direction in this regard. Set stern, but reasonable deadlines for your releases, manage a blog documenting the process, invite others to use your applications (friends are fine, as long as they will give honest feedback), etc... Doing all of these things will keep you excited about your project, focused on your project, and you'll absorb a lot more of the techniques than if you just fleshed out your initial idea and say "<span class="blsp-spelling-error" id="SPELLING_ERROR_5">Meh</span>, that's cool I guess...".<br /><br />Hope this helps.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1968162265124958136.post-75552257047848245722008-03-04T16:51:00.000-08:002008-04-25T15:15:55.615-07:00College CoursesWhen I transferred to my current school last year, I heard a big buzz about a change in the department from C++ to Java. At my previous school (a very, very good one), Java was the focus of the curriculum. We did a lot of advanced things with Java, and although I don't use Java as my primary language, I learned a lot about programming. C++ was used to teach pointers primarily, but some of the <span class="blsp-spelling-error" id="SPELLING_ERROR_0">OOP</span> concepts were also presented of course. Now, the difference between that school and the one I'm at now is that this school is on semesters instead of quarters. At my old school, you could ideally finish all of your Java courses in your first year of school, thus opening the door for more specialized courses that didn't force you to use a certain language. The main issue of this post is to discuss the programming curriculum that I think should be in place in most schools, but isn't.<br /><br />Below is a basic outline of the flow of programming courses that I would prefer be offered:<br /><br /><ol><li><span style="font-weight: bold;">C</span> - Focus on basic programming logic, functions, recursion, arrays, and introduce <span class="blsp-spelling-error" id="SPELLING_ERROR_1">structs</span>.<br /></li><li><span style="font-weight: bold;">C++</span> - Pointers and memory management, heavy focus on <span class="blsp-spelling-error" id="SPELLING_ERROR_2">OOP</span> from novice to expert topics. I would choose to wait until now to deal with memory management because a lot of bad habits get formed when you do this stuff in C without knowing what you're doing.<br /></li><li><span style="font-weight: bold;">Java</span> - Heavy focus on interfaces/abstract classes. The most confusing things to most people in Java is having to extend the standard library, override functions, etc...<br /></li><li><span style="font-weight: bold;">C#</span> - With this language coming into popularity, it's a must have.<br /></li></ol>So, what's my logic here? I believe in starting from the ground up in order to establish good habits and strong skills. I began teaching myself C++ when I was in 8<span class="blsp-spelling-error" id="SPELLING_ERROR_3">th</span> grade. By the time I was forced into taking a Java class, I had no problem whatsoever picking it up. Take the inverse of that. Nearly everyone I've talked to that started programming in Java has struggled in C++ and/or despised it. Why? Java hides too many details from you that become your responsibility in C++. Basically, if you can code in C++, you can code in anything. I don't think you can honestly say that about Java. This is of course a general statement, this isn't to say that there aren't plenty of intelligent people out there that can program in any language, because of course there are. In fact, any programmer worth his weight can, and should be able to program in any language. The point though is that when you are teaching the material, it would be more beneficial to start with C/C++ and then simply learn the nuances of Java from there. The beauty of the above outline is that it allows you to move on to more specific topics such as data structures, GUI, threading, etc... and by the time you get there, you are armed with knowledge of 4 programming languages. The current trend seems to be to teach a particular course with a particular language in order to kill two birds with one stone. I'm not a big fan of this. I think someone is far better off coming into a data structures course with intimate knowledge of at least 2 programming languages as opposed to being expected to develop that knowledge of a language while at the same time mastering data structures. In addition to the above diagram, I think a school should offer at least 2 scripting languages and <span style="font-weight: bold;">require</span> one for a degree. Python, Ruby, Perl all come to mind.<br /><br />My main concern is that a lot of kids will graduate from school with zero ability to program in anything other than Java. That's more of a reality than you may think, especially when C++ is essentially being removed from the curriculum of some schools. The bottom line on this is that C++ is widely used, and that isn't going to change. In fact, in some areas of Computer Science, namely Game Programming (console/PC), C++ is king.<br /><br />More and more I'm finding kids in my CS courses that have never done a lick of programming work before coming to college. The market is always good for Computer Science, so they decide to pursue it as a career. These are one of groups of people that I have in mind when I say you can't go from Java and learn any language. The popular argument against this is that C/C++ is too complicated for these people. Maybe so, but I don't agree with that if the course is taught properly. Secondly, think of it as a "weed-out". It seems the popular choice for a "weed-out" course at a number of schools is discrete math. While I understand the concepts presented are important, I don't view them as things that are specific to this course. I think you garner all of the logic you need to in your programming courses/experiences. Secondly, I don't think this course serves as any sort of useful primer for a data structures course, and at a lot of schools that is how they have the <span class="blsp-spelling-error" id="SPELLING_ERROR_4">pre</span>-<span class="blsp-spelling-error" id="SPELLING_ERROR_5">reqs</span> set up. The only logical reason to do that is to "weed-out" kids that may not be cut out for this line of work. I think a more useful test would be teaching C/C++ as a first language as opposed to Java. <span class="blsp-spelling-corrected" id="SPELLING_ERROR_6">After all</span>, if you can't design and write solid code, you won't have a job very long. Anyone can sit down and work out logic puzzles.<br /><br />Just my two cents.Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-1968162265124958136.post-82826421587993309312008-03-03T07:55:00.000-08:002010-04-07T17:30:25.467-07:00Why put a go-kart engine in a Camaro?I was browsing some projects on Sourceforge yesterday and I came across a basic game of Checkers. I believe they were using GTK and maybe SDL as well. All of the source files were C++. Now, SDL works natively in C++, but as far as I know, you'd need to use GTKMM in order to write GTK code in C++. Nevertheless...<br />
<br />
This person usesd absolutely NO features of C++ in his code. It was all straight-C. I really don't understand this at all. Why incur the extra overhead of the standard C++ libraries and then not use them? Secondly, why use C if you don't <span style="font-style: italic;">need </span>to? When I say that, I'm referring to the need to do a lot of low-level memory manipulation, in-line assembly, and other things of the like. Of course, any of that stuff can be done in C++, but usually C is preferred. This application had none of that in it. It was just a bunch of structs, char*'s, and SDL/GTK library calls.<br />
<br />
My stance on this particular instance is to just use C++ instead of simply changing the file extension to ".c". std::string is a lifesaver, and the C-style structs just get clumsy and very limited after a while, especially in a game. Those 2 things alone would have made the game more extensible, easier to maintain, and a lot easier to understand.<br />
<br />
Just my two cents.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1968162265124958136.post-45904032547540273852007-06-14T19:04:00.000-07:002008-03-03T20:02:36.695-08:00The Contract Job From HellIt seemed easy enough. That's what I thought when I received an e-mail from the Computer Science chair at my University advertising a C++ programming opportunity involving a fairly simple <span class="blsp-spelling-error" id="SPELLING_ERROR_0">API</span> to interface with a radio receiver card. The details weren't great, so I replied and said that I'd like to get some more information. About 2 weeks later I heard a reply from the CS contact person. I was given the contact person for the job, the person actually doing the hiring. I shot off an e-mail asking a few preliminary questions such as the features he'd require, the <span class="blsp-spelling-corrected" id="SPELLING_ERROR_1">time span</span>, the pay, etc... The reply this time was fairly quick, and the job was sounding relatively do-able.<br /><br />There were a few catches though. First, the programming would need to be done on a Windows computer and he would require some <span class="blsp-spelling-error" id="SPELLING_ERROR_2">TCP</span> communication with the data I'd be working with. I'd never programmed under Windows, and I'd certainly never done anything with Windows sockets. The other problem? They needed the entire project done in 3 weeks and they were only able to pay for 10 hours of work per-week at the University minimum wage of $5.50. Dealing with that insulting pay is one thing, but actually expecting someone to come in and write code for an arbitrary <span class="blsp-spelling-error" id="SPELLING_ERROR_3">API</span> in very little time is something completely different. On the other hand, I was a poor college student, and the actual programming didn't seem like it would be much of an issue at all so I figured I'd give it a shot.<br /><br />I shot back an e-mail stating my concerns about completing the project in such a short amount of time, stating that it would probably require a number of hours that they weren't able to pay for in order to do it. About 2 weeks went by and I heard nothing. I assumed some other student had also responded to the e-mail and opted to sell their soul for $165. Then, 1 week before the <span class="blsp-spelling-corrected" id="SPELLING_ERROR_4">original</span> 3 week "deadline" I receive an e-mail from him saying that they can raise the hours to 15 per-week, but they need it done in 3 weeks (again). By this time, mid-terms are in full swing and I've got major programming projects for school to complete. I tell him flat out that I just don't have time now, but talk to me in May when school ends, I'll be available for the entire month. Again, I heard no reply from this message.<br /><br />Fast forward an entire month. They inform me that they "finally have time to get the card programmed" and wanted to know if I was still available until June. I thought long and hard about this. I had just finished a demanding year of school, and 2 very advanced programming projects. I was burned out. I needed a break. I also needed money. By my math I'd make around $300. I took a deep breath and sent off an e-mail stating that yes, I was available until June. As was par for the course, it took him a week to reply to me. Just how important is it to get this thing done?! Honestly, their deadlines came and went as I waited around for e-mail replies from this guy.<br /><br />Anyways, we got everything arranged and I met with him to pick up the equipment. This consisted of a really old piece of junk computer (the card used an ISA slot), a matching really old piece of junk monitor, and 2 antennas (high and low frequencies). Being of rational mind, I decided I'd do all of the core programming on my Linux box, use boost for the <span class="blsp-spelling-error" id="SPELLING_ERROR_5">TCP</span> communication, and then move over to my high-end Windows <span class="blsp-spelling-error" id="SPELLING_ERROR_6">XP</span> machine to add in the <span class="blsp-spelling-error" id="SPELLING_ERROR_7">API</span>-specific code. I wanted no part of using the computer they gave me for anything more than trying out the final code. I encountered a pretty serious problem right off the bat: The card had 2 inputs, a <span class="blsp-spelling-error" id="SPELLING_ERROR_8">BNC</span> and a <span class="blsp-spelling-error" id="SPELLING_ERROR_9">SMA</span>. The problem? Both antennas had <span class="blsp-spelling-error" id="SPELLING_ERROR_10">BNC</span> connectors. The project description as given would not be possible with this setup as both antennas needed to be used at once. I sent off another e-mail informing him of the issue and he promptly replied asking <span style="font-style: italic;">ME</span> what he needed to buy, and to let him know and he'd get it. Reality check: I'm a programmer. I don't know anything about this stuff! I was brought in to write code that performs the task at hand. Troubleshooting <span class="blsp-spelling-error" id="SPELLING_ERROR_11">BNC</span>/<span class="blsp-spelling-error" id="SPELLING_ERROR_12">SMA</span> antenna connectors doesn't really fit in there anywhere. Nonetheless, I did a quick Google search and located 2 links that offered some adapters. I sent them to him and told him he needed to check into the matter further, and to let me know when he had acquired them.<br /><br />One week goes by. Two weeks go by. I send him a status update on the project, pose a few other questions to him regarding his desired requirements. A third week goes by. A month goes by. At this point I'm convinced he's at the bottom of a lake somewhere. I see no other reason to ignore e-mails that only serve to <span class="blsp-spelling-corrected" id="SPELLING_ERROR_13">accomplish</span> a task that he needs completed. I keep chugging away at the code, making my own decisions about the questions I'd posed to him. I got to a point in which I was ready to test the code on the old crappy machine. I shit you not, the video card would not kick in. That's right, I'm given improper equipment, the contractor goes "<span class="blsp-spelling-corrected" id="SPELLING_ERROR_14">Amelia</span> Earhart" on me as soon as I get started, and the computer I'm supposed to develop for doesn't even <span style="font-style: italic;">WORK!</span><br /><br />I send out a 3rd e-mail stating that I've finished the code as much as possible, and that I can't test the <span class="blsp-spelling-error" id="SPELLING_ERROR_15">API</span>-specific code due to the computer not working. I finally get a response stating that he was finishing up a trip in New York and that he'd be in town in a few days. At that point we were to meet and try to get another video card working. A few more days went by, and finally, we were set to meet. 9am, Thursday.<br /><br />I arrive at about 10 till 9 and head upstairs where we met the first time. He works in a musical instruction type of building. Due to all of the expensive equipment, you can only access part of the second floor, the rest is locked off by 2 doors at opposite sides of a winding hallway. My process for handling this in the past was to knock at one door, wait, walk to the other end and knock, wait, then repeat. With each trip, my knocks get louder and louder. Now, you may be shocked as I was, but it was 9:30am and he <span style="font-style: italic;">STILL WASN'T THERE</span>. I really should have known. Being relatively amused by the whole situation, I decided I'd get creative.<br /><br />As I said, I was in a musical instruction building. This meant there were practice rooms all along the hallway, wide open. With pianos in them. There was never anyone on this floor of the building, either. I figured what better way to get someones attention in another part of the building than to start playing piano? So, I did just that. I sat down, and I just played. My basic line of thinking was that anyone that would be important enough to notice me playing piano and arrive to yell at me would also be important enough to have keys to unlock the door I needed to get into. I gave up after 5 minutes and decided to just leave. As I walked out the front door, I see the contractor walking up the sidewalk. Just a simple "Hi how are you?". I spent the rest of the day explaining all of the code and documentation to him, and never once did he mention being nearly an hour late.<br /><br />The job is done now, and I feel very relived, to say the least. I accomplished a lot, I learned a lot, and I ended up making close to $500. <span class="blsp-spelling-corrected" id="SPELLING_ERROR_16">Despite</span> everything, I made sure that I wrote the best code I could, and gave the most informative and helpful documentation possible. At the end of the day, I even like the guy, he's very intelligent, and I'd be "more than happy" to do some future development on this project for him. Of course, if he reads this, he'll <span class="blsp-spelling-corrected" id="SPELLING_ERROR_17">immediately</span> know it's about him, but I suppose that's fine. He got the best $500 custom software package imaginable.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1968162265124958136.post-4812486424570175672007-06-07T10:05:00.000-07:002007-06-07T10:33:31.070-07:00Careful with those stubs, mister!This is just a tiny snippet which ties into my <a href="http://zachelko-programming.blogspot.com/2007/06/attention-this-is-only-warning.html">last post</a> about compiler warnings.<br /><br />Frequently when I'm building a class, I'll stub out a lot of the functions just to get an idea of how things will work. "Stubbing" simply means adding the function declaration/definitions, but instead of having the function actually perform it's task, it's usually either left blank, or does a print statement to show where the control is currently at. That's all fine and well...until you do something like I did.<br /><br />In order to complete my stubbing, I went as far as to assign one of my class data members, an std::vector<>, to the return of the function that would be used to populate this vector. The problem? While stubbing that said function, I forgot to add a return value! This, coupled with lack of any compiler warning flags, caused a segfault when I ran some testing code.<br /><br />Now, to the heart of the matter: Why was this so hard for me to track down, aside from improper (absent) warning flags? I was doing my debug print statements with std::<span class="blsp-spelling-error" id="SPELLING_ERROR_0">cout</span>. The problem? std::<span class="blsp-spelling-error" id="SPELLING_ERROR_1">cout</span> is buffered, which means things get printed when the OS decides they get printed, not exactly when you tell it to print. After I tried to <span class="blsp-spelling-corrected" id="SPELLING_ERROR_2">initialize</span> my vector from the function (of which returned nothing), I made a call to some other class functions, and due to the buffering of my debug statements, it seemed the segfault happened AFTER that other class function returned, but BEFORE control was given back to the constructor that called it. This clearly made no sense, and all of the code looked fine.<br /><br />Using std::<span class="blsp-spelling-error" id="SPELLING_ERROR_3">cerr</span> is the optimal choice for debugging output because it gets printed exactly when you tell it to. More importantly, a simple -Wall flag to g++ would have informed me right away that: <span style="font-weight: bold;">"control reaches end of non-void function" </span>and immediately I'd know why my program was <span class="blsp-spelling-error" id="SPELLING_ERROR_4">segfaulting</span>.<br /><br />So, lessons learned?<br /><br />1. Enable. Compiler. Warnings.<br />2. Use std::<span class="blsp-spelling-error" id="SPELLING_ERROR_5">cerr</span> for debugging output<br />3. Complete your stubbed functions with return values and proper parameters<br /><br /><span style="font-style: italic;">Note: I've been told that using std::endl</span><span style="font-style: italic;"> will force std::</span><span style="font-style: italic;" class="blsp-spelling-error" id="SPELLING_ERROR_7">cout</span><span style="font-style: italic;"> to be printed, but for whatever reason that just wasn't happening for me. *shrug*</span>Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-1968162265124958136.post-20056237300596553662007-06-07T09:21:00.000-07:002007-06-07T10:30:51.664-07:00Attention: This is only a warning.I tend to be pretty lazy when it comes to compiling my code. After I'm done knocking out the source, I want to make sure it compiles right away, and start testing it. However, taking the 10 seconds to add warning flags to the compile command could save me, and you, countless headaches trying to track down a bug that the compiler would have been able to point out right away if given the proper flags. The following example, unfortunately, is immune to compiler warnings, but it illustrates a basic error that compiler warnings would try to prevent you from making.<br /><br />I was writing an application that dealt with <span style="font-style: italic;">unsigned integers</span> throughout the entire program. At some point, I needed to convert those <span style="font-style: italic;">unsigned integer</span> values into <span style="font-style: italic;">std::strings </span><span>via a helper-function that I created</span>. The values were read in via a binary file, and stored in <span style="font-style: italic;">unsigned integers</span>. The deadline was approaching, and I didn't think about what would happen if there was a negative value in the binary file (perfectly legal, though) The result? The compiler silently converted the <span style="font-style: italic;">int</span> that I retrieved from file to the <span style="font-style: italic;">unsigned int</span> it was being stored in, thus mangling the sign value on my data. Luckily for me, I had been programming on a daily basis for many hours for about the past 5 days, so my brain was warmed up and I caught the error rather quickly. However, it isn't hard to imagine how something as minute as this could remain hidden for a long time, delaying the completion of your project, and driving you farther into insanity. Again, this particular mishap is unfortunately immune to warnings, but from this you can see how something of this sort could be avoided by enabling proper warnings.<br /><br />There are many other error flags, please check the docs for your compiler to see what they are, but it should be a goal to not only use these flags at all times, but also to have your code compile with the strictest of warning flags in use. If you are receiving a compiler warning, there is a good bet you have a problem with your design, implementation, or maybe both. The above scenario would really be classified as design/implementation, depending on how you look at it, but really it was just a case of carelessness.<br /><br /><span style="font-weight: bold;">Enable compiler warnings with the needed flags. Get rid of them with better code.</span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1968162265124958136.post-63490305824224252862007-05-31T19:04:00.000-07:002010-04-02T19:49:37.170-07:00Down PeriscopeHello. You've somehow stumbled upon my programming weblog. In this area, I hope to share with you various experiences I've had writing software. For this introductory post, I'll turn you on to something I was shown yesterday evening. I was so shocked/amazed/excited when I was shown this "trick" that I exclaimed aloud numerous times...<br />
<br />
The issue I was having in my code involved objects being duplicated (copied) as I stored them in a std::vector. Oh, by the way, I code almost entirely in C++. Anyways, the way this bit of code worked was that a line was read from file, and that line was then used to construct an object of my type. From there, those objects were added to the vector. The problem was, those original objects stuck around, so I'd have <span style="font-style: italic; font-weight: bold;">TWICE</span> as many objects in existence than I was actually using! I asked for some assistance on IRC and I must say, my life has never been the same.<br />
<br />
<b>The "Trick"</b><br />
<br />
Maybe I've just been living under a rock, but I had never seen this before. Apparently, you can arbitrarily create scopes anywhere in your code! I'll demonstrate it below with a basic example:<br />
<br />
<script src="http://gist.github.com/354009.js?file=scope.cpp"></script><br />
<br />
<b>Output</b><br />
$ ./scope<br />
ctor<br />
dtor<br />
Only 1 Foo object exists at this point, good!<br />
dtor<br />
<br />
Now, instead of having 2 copies of <i>foo</i> in existence (the one I create, and the one that gets copied into <i>foos</i>), I only have the one inside of <i>foos</i>. Depending on your situation, this is preferable because if you need to add an object to a vector, chances are good that you'll be referencing it from within the vector for the rest of the program.<br />
<br />
Hopefully you learned something from this, stay tuned, I'll soon be posting a very amusing and interesting story about my recent job as a contract software developer. Take care.<span style="font-weight: bold;"><br />
</span>Unknownnoreply@blogger.com3