So, naming scheme aside, my "MatPolygonDraw" function is quite a capable function. It defines the vector of colors used to determine the fill color of the polygon in question, it draws the labels for each point, the bounds of the full shape, and the lines connecting each point to the maximum value for that point. In achieving these goals, it takes an input string, checks it for validity, determines its numerical value, converts the numerical value combined with its string position to work out the variable the value applies to and then determine X,Y coordinates of where that point is.
I'm sure it does more, but, meh, I'm still working on it so there's no need to keep explaining it. I updated it today to contain a nested class entitled matButton, a subclass of the JButton. Now, rather than creating a new JButton and assigning it an actionListener to make everything work as it should, the frame that hosts the MatPolygonDraw instance simply calls the getButton class, passes any pertinent information over, and receives a new JButton appropriately configured for the task.
Tomorrow will see the expansion of this concept. Rather than just the the JButton, I'll include the JTextField component and place both of them on a panel. This way I'll just call getInputPane or whatever I decide to name it and I'll receive both of these, properly configured. I'll do the same to create a getEditPane for manipulating the material's properties, and any other panes I may need to accomplish any task I can imagine that requires a material graphic interpretation.
Then I just make the structure for any other objects that need manipulation, I go ahead and follow the same process for getting the necessary interfaces, and voila, simple finished product.
In other words, I think I'm getting this, because suddenly I'm realizing just how little work I'll have to put into the final assembly of everything compared to the creation of the manipulating classes.
In all, I'm content. It's time for bed though, and that leaves this post open for discussion. Any recommendations for a better name for this class? Preferably something that defines what it does, very concisely. Best name gets immortalized in my code! And... a cyber cookie?
P.S: I'm going to stop going ridiculously overboard on the tags for my posts. They're all about computing, no need to continue labelling that.
Showing posts with label names. Show all posts
Showing posts with label names. Show all posts
Wednesday, 3 March 2010
Wednesday, 17 February 2010
Why God Invented Energy Drinks (and Brain Food)
Today was a pretty unproductive day. It's not for lack of trying. It started with a bit of (non-programming) group work, which was handed in way too late. Me being the manager, I stayed up late, got two hours of sleep, and went right back into finishing the job.
Programming on two hours of sleep is not easy. In fact, if you ever have the choice, don't do it unless you're looking for frustration. In my lack of experience on this matter, I was happily back to work on my ISA Calculator (MATLAB), programming the GUI to display a table of values for a user-input height range.
I kept getting a run-time error along the lines of "array indexes must be real, positive numbers." I finally narrowed it down to one particular snippet that was causing the error: length(a).
If you know a little about programming, you probably know that length() functions simply determine the length of whatever's inside the parentheses. Basically every language has it built-in. MATLAB specifically uses the length() function to tell you how many different values there are in an array. In other words, it can't go wrong. I even confirmed that a was defined, had a value and a size. Length(a) simply wouldn't work.
Well, after an hour of head-scratching, I gave up. Hours later (still no sleep), I went back to it and again could find no solution. I then went to irc.freenode.net #matlab and asked for help. They agreed. There was nothing wrong with the code, and the length() function can't cause that error in the situation I put it in. (Thanks to CrimsonScythe for going all-out to track down my stupid mistake!)
Well, turns out it can. I used the string variable called length to store the name of units of length (meters). It was declared very early in development, and very early in my program, and basically got hidden away. This was the first nested function I wrote in my calculator, coded inside the overall function so that it has access to all the variables in the main function easily, and therefore it was the first one that noticed this oversight on my part. I now feel bad for MATLAB as I'm clueless as to what it was trying to do with my little variable-gone-function. Rather than a square peg in a round hole, I think it was more like replacing a screw with super glue. It might pretend to work, but, really, when it comes down to it, it's going to fail, and in a pretty catastrophic way.
So, that out of the way, my loop worked! I'm done! Right? No. Because the loop worked, sure, but the outcome wasn't what I needed. Why not? Because, after 20 minutes of searching, I realised I had this in my code:
for q=1:length(t)
mu = t(q) * (constants);
end
Assume the math was right, as (constants) here is a bit more complicated in my code. Anyone catch my mistake?
for q=1:length(t)
mu(q) = t(q) * (constants);
end
That'd be the right answer. MATLAB was happily doing the same equation multiple times over with different numbers, but it was storing it all to the same place. In other words, where my other variables had 11 values, mu had only 1. Fun stuff. Also, note that this kind of error is the thing that any book or teacher will tell you is a common beginner's mistake. I am a beginner, I admit. But I promise you, this is a common mistake in general. Small detail, easy to miss.
So that's fixed. My table works! Right? No, of course not. I'm still not sure why not. The first column works fine. The first row works fine. But columns 2 through 8 in any row after row 1 are blank, with the values instead inserted into new columns after column 8. No real reason I can see. Go figure. My buddies on IRC have gone to their own tasks and so I'm left clueless. I'm going to bed. Maybe when I'm rested this will make sense again.
There's a tip I heard very early on in programming: no matter how short your program is, there's bound to be a bug. In fact, my first "Hello, world!" program in Java utterly failed on me, though the reason is lost to the failings of my memory. This is just one of those situations. For the past week my MATLAB work had no real problems, so this is just everything catching up to me.
Tomorrow should be the final day of development for this MATLAB project, at least in terms of the official requirements (I do have some smaller features I'm interested in adding to it after the fact). It should be... eventful, but we'll see.
Labels:
computing,
matlab,
names,
programming,
technology,
variables
Subscribe to:
Posts (Atom)