For once, I want good integer subtyping!

June 3, 2007 at 6:00 pm | In Java, Programming | No Comments

I am using an integer ID in parts of my program, I want to ensure that the ID is an actual ID that I have returned.  In a strongly typed language that also has a well fleshed out subtyping system, this would be trivial!

subtype AlbumID is long

The benefit of course would be that I could keep track of my AlbumID types and not have to worry about anything else!

Now the proper Java way is to make a new class called AlbumID that has a single long field and…  bleck!  I just want compile time checking darnit, I don’t need anything instantiated.

Awesome use of issue tracker’s “attach file” feature

May 8, 2007 at 2:27 pm | In Java, Programming | No Comments

I have discovered an awesome use of the “attach file to issue” feature that most issue trackers support.

.swf repros of issues.

The open source <a href=”http://www.camstudio.org/”>CamStudio</a> program comes with SWF Producer.  Nativly CamStudio generates .avi files, but hey, why stop there?  AVI files are a pain in the rear to get working cross platform*, so I convert them to .SWF, which is not only smaller (No clue as to why that is!) but work on all platforms.

Kind of sad that it took Macromedia (now Adobe) to unify cross platform video, but hey, whatever works!

The only issue I have run in to so far is file size limitations, the issue tracker being used over on java.net only allows files up to 1Meg in size.  Luckily my Video-Kung-Fu is good enough that I can get most videos under that size, but I do not really expect other people on my team to be able to pull that off.

* Or even cross computer, who knows what codecs different team members have installed.

My Project: Status Update 3

January 8, 2007 at 11:44 am | In My Project | 1 Comment

Actual implementation has begun!  Going along quite well.  Having a design to work from is really helping me avoid stupid mistakes from the get go.
Items to Accomplish       /    Percent Complete

  • Choose Platform:  100% (Done)
  • Setup Platform: 100%
  • Choose libraries:  95% —
  • Integrate libraries into project: 65% — Most libraries are currently in use, one still needs to be integrated.
  • Program base algorithm:   65% — Methods are in place, and most of the program logic is there.
  • Choose test case:  45% — About half the test cases have been decided upon.
  • Program test case:  5% — Stubs in place to latch on to for performing tests.
  • Choose performance measurement tool: 15% — Additional research has been performed.
  • Integrate performance measurements:  0%

My Project: Status Update 1

December 16, 2006 at 1:26 pm | In My Project | No Comments

Spent a lot of time researching various aspects of linear computation, at the expense of a headache.  The ability to pick up a topic rapidly comes with its downsides as well…

Items to Accomplish       /    Percent Complete

  • Choose Platform:  100% (Done)
  • Setup Platform: 90%
  • Choose libraries:  65% — Research started on second library, learning about options available
  • Integrate libraries into project: 0% — Need to finish choosing libraries first
  • Program base algorithm:   10% — Algorithm code outlined
  • Choose test case:  5% — Some thought has gone into it, but it needs more investigation
  • Program test case:  0%
  • Choose performance measurement tool: 2% — I have heard of some of these, but need to investigate them more
  • Integrate performance measurements:  0%

My Project: Initial Status

November 28, 2006 at 2:20 pm | In My Project | No Comments

I am working on a project, of which I am not going to go into details about.  These blog entries serve to mark my progress.

Items to Accomplish       /    Percent Complete

  • Choose Platform:  100% (Done)
  • Setup Platform: 80% — Need to finish minor details, but ready to start development if another hour or so does not lead to results
  • Choose libraries:  40% — I have one library in mind that I have used previously, but I need to investigate it more to see if it can handle the load I am going to be placing on it.  I need to start looking for the second library still
  • Integrate libraries into project: 0% — Need to finish choosing libraries first
  • Program base algorithm:   0%
  • Choose test case:  5% — Some thought has gone into it, but it needs more investigation
  • Program test case:  0%
  • Choose performance measurement tool: 2% — I have heard of some of these, but need to investigate them more
  • Integrate performance measurements:  0%

Response to: Making a mountain out of a molehill (of bugs)

September 27, 2006 at 1:58 pm | In Programming, technology | 1 Comment

Letting bugs pile up is bad. This should be obvious.

My internship last year was lucky in two ways. The first was that the company was in a bug squishing phase, so I could count on feedback to my bug reports sometimes in a manner of hours.

The second bit of luck was that as a developer, I was able to gain a comprehension of the underlying foundations of the system. Using this comprehension, I was able to break the system in many creative and painful ways.

Examples include realizations that a particular operation was not truly atomic (DB corruption issues), to my favorite when I caused a buffer overflow by installing the Japanese Language Pack and started writing hiragana characters in to fields that expected just English text.

The Japanese exploit was my favorite one, if solely because it allowed me the opportunity to witness first hand (but not have to be involved in the fixing of!) the results of making assumptions about a user’s nationality, and about something so simple as how big a char should be. Using Unicode 100% through an application can be difficult, it only takes a single call to a function in some API that assumes 8 bit chars to break everything. Of course everyone knows that by now, but who actually tests it to that extreme?

Giving bug reporters quick feedback is essential for a programming team to do. QA is your enemy, and they are also your best friends. Remember that QA’s job is to poke you with a sharp stick now, so that you do not end up blowing off your entire leg with a shotgun later on down the line!

Why Office 2007 will be a failure

September 27, 2006 at 1:36 pm | In C#, Microsoft Office 2007, Office 2007, Programming, technology | No Comments

Let me start off by saying that the interface rocks. Use it for awhile, then go back to an application that is structured around menus, and there is this giant feeling of “What have we been doing for all these years? The entire industry is stupid!”

The interface is that good.

But Office 2007’s downfall will be the same downfall that Office XP had, and the same massive problem that Open Office has:

Slow load times.

A common use for Word is to spell check random bits of text. Click the blue W, [cntrl-v], [f7].

Under Office 2007 that procedure is now Click the blue W, [Whistle show tunes], [take a short nap], [cntrl-v], [f7]

Once any of the Office 2007 applications get started up they perform well (though Outlook has some minor performance issues) and yes there are performance gains to be had once the code base is cleaned up and readied for release, but those minor speed gains are not likely to offset the overall slow load time for what users expect to be a very simple set of applications (Write text, add numbers together, send and recieve email).

It is important for developers to remember that ultimately the users do not care how eloquent our code base is, they just care if the software delivers the desired functionality. Does eloquent code enable rapid deployment of features that the users desire? Often times yes, but if a user can load up a web app in less time than it takes to load up an eloquently programmed desktop application, well, which one do you really expect the user to use?

Power comes at a price

August 29, 2006 at 2:47 pm | In Programming | No Comments

Going through the Python tutorial again:

Tuples can be used as keys if they contain only strings, numbers, or tuples; if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key.

Well OK, that sounds reasonable.  You can’t use an object as a key if it keeps changing, right?

Oh wait, I can in Java.  I define a Hash function, done.

I have only had to use this once, and it was for a rather baroque situation, but it was rather cool that I could do it, and fairly simple as well.  Just pick which non-mutable instance variables of the class that should be used to generate a hash value, and shove them into a hash function.

What is the difference between these two methods of calling?

August 28, 2006 at 10:06 am | In Programming, technology | No Comments

Edit: I have added an explation of (the more typical) Call by Value vs. Call by Reference since everybody who comes to this page seems to be looking for it. :)

Call by Value VS Call by Ref explanation:

Variables all have a value. For instance:

int a = 5

Here, a has the value of 5.

Now realize something. THERE IS NO VARIABLE CALLED a. The second you hit compile (build), that variable vanishes. What really happen is that when your program is run, 32 bits (4 bytes)[1] of RAM inside the computer is allocated, and the value 5 is stored there. The compiler automatically figures out what address of memory to use.

From the computers point of view, it may very well decide that the memory address 4c00h is where the variable a always goes, and when that above line of code loads, it may looks something like this:

MOV 4C00h 5

4c00h is an address in memory, and 5 is the value that is placed there. mov is the assembly[2] command to move data into memory (amongst other things).

The compiler replaces all your usages of the variable a with the memory address 4c00h. The point here is that variable names are just a label that is there so we don’t have to try and remember memory address numbers.

This is a BIG deal. You have to separate “Variables” from the concept of “Values”. They are two different things. Remember this: A variable is just a way for US, the humans, to LABEL SOMETHING that is stored inside the computer.

You will notice that a relates directly to a a number in this case. Hey, cool. That is easy to understand.

There is no rule saying that variables have to always label just numbers or string. Variable can label darn nearly anything.

Think for a minute. What are functions? They are a label we apply to a bunch of code that we want run. We want that code run, type in the function name, the compiler goes and inserts the instructions needed to make it so that the function is run.

This is also pretty simple. Here, variables just label functions. Not too complicated.

What if we want to label something more complex though? Like say an Array? Arrays can have many values inside of them, and they can take up a lot of memory.

int[5] hoursWorked = [8, 9, 7, 8, 8]

The compiler cannot just go through and replace all occurances of hoursWorked with a single address of memory. Now, hoursWorked is taking up a lot of addresses in memory!

Thankfully, (I am not going to explain this right now. :) ) arrays are setup in memory so that all the values are right next to each other. This means that the compiler goes

MOV 4C01h 8
MOV 4C02h 9
MOV 4C03h 7
MOV 4C04h 8
MOV 4C05h 8

If you ignore the h at the end there (it is just shorthand for something else, if you know what, great! If you don’t don’t worry about it. ;) ) you can see that the numbers are increasing. 1, 2, 3, 4, 5. This means that if you could look at the values stored in RAM on your computer, you would see the numbers 8, 9, 7, 8, 8, all lined up right next to each other.

Here is the cool part. We ONLY need to have the address of the first element in the array. 4C01h If we know that address, we can find the other ones just by walking forward, remember, they are all right next to each other!

So what does any of this have to do with passing values in functions? Well, quite a bit!

Lets pretend we have the following function:


int calculateSalary( int numberOfDaysWorked, int[] hoursWorkedEachDay )
{
  int totalPay = 0;
  int hourlyPay = 7;  for( int i = 0; i < numberofDaysWorked; i++ )
{
totalPay = totalPay + (hourlyPay * hoursWorkedEachDay[i]);
}

  return totalPay;
}

This function simply goes through the array of how many hours you worked each day, multiplies the hours of each day by how much you earn each hour (in this case, $7), and adds that days pay to the weeks total.  Notice if you only worked 4 days, you pass in numberofDaysWorked as 4, and you only read the first 4 values from the array.

The function most likely will get called like this:

int totalPay = 0;
totalPay = calculateSalary(a, hoursWorked);

I use a and hoursWorked from above.

The variable a is pretty simple.  The compiler can just read whatever value is at the memory address a refers too, in this case the memory address is  4C00h and the value is 5.  The computer just reads the value at memory address 4C00h and passes it to the function calculateSalary.  Cool.  Wenow have

 totalPay = calculateSalary(5, hoursWorked);

What about the array hoursWorked?  The compiler cannot just copy a value here, it is an array!

So what happens is that the memory address of the array is passed instead.  It ends up looking like

totalPay = calculateSalary(5, 4C00h);

4C00h is a reference to where we can find the array at.  If you look up the definition of reference, it says that:

a reference is something that refers or points to something else

en.wikipedia.org/wiki/Reference

Well, that is exactly what 4Cooh does, it POINTS to where the array hoursWorked is at in memory.

In languages like C and C++, you say that something is a pointer by putting the character * in front of it.  Newer languages (such as Java and C#) handle a lot of this for you, and when you pass an array, you don’t have to worry about syntax so much.

Oh, and you now understand pointers too.  :)  I have work to do, my apologizes for the lack of spell checking.

[1] This is a vast simplification and may not be true on all computers. INTs can be of any number of sizes, PLEASE DO NOT RELY UPON INTS BEING 32BITS IN SIZE. Especially not because I said so. :)[2] Assembly is a human readable represenation of the language that your computer understands, actual machine code. Machine code is all in binary and consists of 0’s and 1’s, and is even harder to understand! And yes, this example is greatly simplified.


Original post is below, you can safely ignore it, someone else explained it to me. :) Call by Value (where the value is always an object reference, not the value of the object)

compared to

Call by Reference

They end up being functionally the same, don’t they?

This is in reference to Python, which then says at the bottom of the tutorial page:

call by object reference

THEN WHY did they just say Call by Value?

Call By Val

Call By Ref

Then there is C’s awesomeness of ALWAYS Call By Val, but we’ll pass the value of a memory address along if ya want cuz hey why not?

I am a proponent for Call By Ref whenever you have objects, since when I am doing OO I want abstraction, but when I am doing C I am in a mood for understanding, comprehension, and I can feel the entire machine surrounding me. It is awesome, it is fast, it is efficient, my code has less bugs, and damnit, I WANT that power because it feels good.

Programming outside of OO seems a bit weird now

August 25, 2006 at 1:05 pm | In Programming | No Comments

It seems strange to be in an environment where functions just “exist” floating out there in the ether so to speak.

It does not seem weird in C, because what C gives you, you pretty much expect to have as a programmer.   But other languages have these huge functions that do not seem to be attatched to an object, then another class of functions that are.   Then I as a programmer have to remember which is which.

Not that having a general “Utility” class with a ton of static methods is any better.

Next Page »

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.