| Shawn's profileSm4kt4rd's SpacePhotosBlog | Help |
Sm4kt4rd's Space |
|||||
|
|
January 12 Windows 7 BetaDespite the fact that I usually do not participate in any Beta programs, this weekend I found myself waiting for Microsoft to release the beta of Windows 7. Someone whose blog I follow, and whose book I have, happened to participate in the GDC this year, and has had the beta since that event. After reading about the reliability of the new OS, and a few improvements in his eyes, I decided I would give it a whirl once it came out. So, here I am, new year and a new OS, that will hopefully not have any problems with VS 2008 or XNA.
I will say this about the installation. I went ahead and made a backup of my Vista installation just to be safe. After burning the ISO to DVD, I did an upgrade of my current Vista installation instead of an out right reinstall. It took forever to do however. I would say, since I was car hunting while the installation was happening, that it took all of 3 hours to complete. Having said that though, everything appears to have came through the upgrade process unscathed. I have not really had a chance to try every installed application, but the preliminaries look very promising. December 17 Tidbits of programming knowledgeWhile I am constantly reading blogs and books and any other sources of knowledge (Stanford's Java Course) to improve my programming skills, I have come across some tidbits I wanted to keep fresh in my own mind until the knowledge sinks in. Hence, a blog post about a couple different things. The first thing is the reference type String and StringBuilder. That is correct, I said reference type. I suppose that is probably common knowledge, but it is something I never really thought about until I read it and heard it. So, why mention String and StringBuilder, why both? Consider the following program: 1: 'VB 2: Dim s As String 3: 4: s = "eggs" 5: s += " milk" 6: s += " bread" 7: s += " butter" 8: Console.WriteLine(s) 9: 10: //C# 11: string s; 12: 13: s = "eggs"; 14: s += " milk"; 15: s += " bread"; 16: s += " butter"; 17: Console.WriteLine(s)Question: Do you realize the .NET runtime is creating a new string four times in this code? Thus, only the last string has a reference, the others will be garbage collected. Solution: Use String's Concat, Join, or Format methods to join string items, or; Use the StringBuilder class to create dynamic strings. With String being "immutable" is where the issue of creating new strings occurs. While the StringBuilder class provides for a "mutable" string. Seems pretty straight forward huh? I leave the string section with this question then:
This next section is just an interesting tidbit about functionality of user defined types (meaning classes in this case). Evidently, it is good programming practice to always override the ToString() and Equals() methods. How many times have I ever done that? NONE! However, in thinking about it, having these two methods overridden in one of my classes can actually provide some functionality to me (the developer that is) during design/testing time. I can dump the contents of a class say into the 'output' window of the IDE just to see values instead of setting breakpoints to step through code, thus providing little snapshots of my class as a program runs. Comparing equality of my class between two different instances, I could see where that would be handy, but probably is something that I would need to think more on reasons to actually use it (although implementing certainly does not hurt anything). One other tidbit to talk about, or memorize for my purposes (prepping for a MS certification test). Always, in a try-catch-finally block, order the catch from most specific to least specific in order. A quick example (in VB) relating to a file not found error: 1: Try 2: Dim sr As StreamReader = New StreamReader("test.txt") 3: Console.WriteLine(sr.ReadToEnd)4: Catch ex As System.IO.FileNotFoundException 5: Console.WriteLine("The file could not be found.") 6: Catch ex As System.UnauthorizedAccessException 7: Console.WriteLine("You do not have sufficient permissions.") 8: Catch ex As Exception 9: Console.WriteLine("Error reading file: " + ex.Message) 10: End Try Hopefully someone finds these tidbits useful besides just me. Happy Coding! December 11 Lesson 3 - Beyond Cornflower BlueHello again! In an effort to continue on, and with no questions at this point, I have chosen to forego a 2.5 vocabulary section. Hopefully enough information is available via the web that most can understand what has taken place up to this point. One thing we can do, and should do, is add using statements to our project. Just as we added references to our solution to let the IDE know where to look for certain types, we can also utilize using statements to enhance our syntax in our code. Notice previously how we addressed things in our Main and Game class with fully qualified names (ie Microsoft.Xna.Framework.....). Making use of using statements at the top of our classes can help to alleviate all the overhead of typing the fully qualified name. At the very top of our program I have added the following using statements and adjusted my code to reflect this addition: 1: using Microsoft.Xna.Framework; 2: using Microsoft.Xna.Framework.Graphics; 3: 4: namespace CornflowerBlue 5: {6: static class MainProgram 7: {8: static void Main() 9: {10: using (MainGameClass game = new MainGameClass()) 11: { 12: game.Run(); 13: } 14: } 15: } 16: 17: class MainGameClass : Game 18: { 19: GraphicsDeviceManager graphics; 20: 21: public MainGameClass() 22: {23: graphics = new GraphicsDeviceManager(this); 24: } 25: 26: protected override void Update(GameTime gameTime) 27: {28: base.Update(gameTime); 29: } 30: 31: protected override void Draw(GameTime gameTime) 32: { 33: graphics.GraphicsDevice.Clear(Microsoft.Xna.Framework.Graphics.Color.CornflowerBlue); 34: 35: base.Draw(gameTime); 36: } 37: } 38: }With the exception of line 33, we have pretty much removed all Microsoft.Xna.Framework references in our code just by including the using statements on lines 1 and 2. Pretty neat, but admittedly not that exciting, the program still does the same thing.... Lets start making some changes to that now. First, lets move our "Game" class out of the "Main" class. To do this, right-click your project name (not the solution name) and select Add and new class from the pull out: You will get a pop-up window that already has a class file selected, and a text box with a Class1.cs already filled in. Give your new class a name, I will call mine MainGameClass just like in our current file, and select ADD. After a few seconds, a new file is added to your solution and project with the filename you gave it. Also, within the editor a new file opens with some statements already included. For our purposes, go ahead and select everything in the file and delete all of it. Since our solution is in a namespace, mine being CornflowerBlue, we do need to include the namespace statement block within our new file. Also, since C# is object-oriented, we need to also include a class statement block in this file (they were already there when we created the class, but we are just adding them back to get a sense of what is needed in class files). If we wanted to, we could actually use a different namespace, and at some point in the future we may actually do this. But, for now, lets set our namespace the same as our Main class (again, to reiterate, mine is CornflowerBlue, yours may be different). Ultimately, I will remove lines 17-37 from our Main file and put them into this file until I have this in my MainGameClass.cs file:
1: using Microsoft.Xna.Framework; 2: 3: namespace CornflowerBlue 4: { 5: 6: class MainGameClass : Game 7: { 8: GraphicsDeviceManager graphics; 9: 10: public MainGameClass() 11: {12: graphics = new GraphicsDeviceManager(this); 13: } 14: 15: protected override void Update(GameTime gameTime) 16: {17: base.Update(gameTime); 18: } 19: 20: protected override void Draw(GameTime gameTime) 21: { 22: graphics.GraphicsDevice.Clear(Microsoft.Xna.Framework.Graphics.Color.CornflowerBlue); 23: 24: base.Draw(gameTime); 25: } 26: } 27: }This is now what my Main.cs file looks like: 1: using Microsoft.Xna.Framework; 2: using Microsoft.Xna.Framework.Graphics; 3: 4: namespace CornflowerBlue 5: {6: static class MainProgram 7: {8: static void Main() 9: {10: using (MainGameClass game = new MainGameClass()) 11: { 12: game.Run(); 13: } 14: } 15: } 16: }You can now press F5 at this point (click Run alternatively) and you will see the program still does exactly what it did before, however we have now started to separate our code into their own distinct files. The 'static void Main()' function in our Main.cs file is still the starting point of the application. The 'game' variable in our using block creates an instance of our MainGameClass.cs class and then calls a Run() function on our game. We did not create a Run() function ourselves in our game, however it is provided for us as part of the XNA framework, so we therefore do not need to concern ourselves with this detail. One other thing before we close this lesson, I would like to talk about game states. When you load up a game on your PC or Xbox, the first thing that usually appears is some sort of menu system (granted there may be some splash/loading screens also). We will continue on with this series by starting out with a relatively simple state system utilizing an enum to accomplish this. For starters, we are only going to utilize two states at this time to keep it simple. Our two states will be Menu or Playing and will be added with this code in our MainGameClass.cs file before the GraphicsDeviceManager declaration. Our final MainGameClass.cs (or whatever you chose to name yours) will look like this: 1: using Microsoft.Xna.Framework; 2: 3: namespace CornflowerBlue 4: { 5: 6: class MainGameClass : Game 7: {8: enum GameState 9: { 10: Menu, Playing 11: } 12: 13: GraphicsDeviceManager graphics; 14: 15: public MainGameClass() 16: {17: graphics = new GraphicsDeviceManager(this); 18: } 19: 20: protected override void Update(GameTime gameTime) 21: {22: base.Update(gameTime); 23: } 24: 25: protected override void Draw(GameTime gameTime) 26: { 27: graphics.GraphicsDevice.Clear(Microsoft.Xna.Framework.Graphics.Color.CornflowerBlue); 28: 29: base.Draw(gameTime); 30: } 31: } 32: }We have not made use of our games state yet, however with the inclusion of the enum, we are now ready for our next lesson to utilize this feature. Happy Coding! December 09 Lessons learned from internshipWell, kind of sort of, my last semester at ECTC (Elizabethtown Community & Technical College) is officially over. I have completed all final exams as of today, though the semester officially ends at the end of this week (Dec. 12, 2008). I thought I would post some thoughts on the internship project that I did this semester.
Thought #1:
Throughout my 2 year program at ECTC, I was taught quite a bit about programming fundamentals. Granted, it was limited in a way, and the languages I studied were aimed at general console programming, nothing OS specific (though at times I had wished they were). Anyhow, I have always been this kind of programmer who sits down and immediately starts coding when given a problem. For the most part, I have never, and to emphasize that NEVER, had any problems at all. Now that this internship is done, I see plenty of spots in my code where I have redundant code. Had I planned out what I was doing in the first place, I probably could have alleviated that redundant code. Maybe a new class to handle file access (which is the main redundancy in my case).
Thought #2:
Development environments vs. "Live" environments. Living in the sheltered world of Visual Studio has its benefits. You do not need to think about user accounts, roles and privileges. That hit home with a quickness upon first deployment of the web site coding I had done. One note about that also (web site coding). I do not make a distinction between writing code for applications to run on a machine, versus code written for a web site. To me, both are programming. Am I wrong or right, I think it is up to individual definitions of what programming is.
Thought #3:
The old adage KISS! Keep it simple stupid. Originally when given this project, the web site side of things only needed a button added to the page. Instead, for me, it was a total web site re-write. Did I have to do that? No. However, if you had seen the previous version of the web site, you would have agreed that the site needed to be changed/updated. However, as a result of the new site, too much time was spent making it work, when originally it worked fine anyhow. That left a time crunch for the application side of things, which was difficult itself since it dealt with threading and serial communication with Cisco routers.
All said and done, while the web site part of the project now looks great, and is a lot more intuitive and robust, it can not be used at this point. The application side that deals with communication between user and routers ended up being complicated enough that I could not get it functioning correctly. Hopefully the professor who was my mentor sees the potential of the new site, and can institute a new internship project to expand upon the solid base that I provided (at least I think it is a solid base, granted a little refactoring can be done).
All of these after thoughts has left me with a bit of hunger for knowledge on programming methodologies. Test driven development....Agile.....what is best, where can I learn the foundations....
Hopefully the next 2 years at my next college (WKU if no one noticed), will provide some more insight and guidance into these areas. Till next time, HAPPY CODING! December 07 Notes to self...Neat little trick I just learned after watching a LVS video and experimenting afterwards:
Response .Write("Welcome " + User.Identity.Name.ToString() + " Platform: " + Request.Browser.Platform + " Browser: " + Request.Browser.Browser);Displays the users PC name and current user signed in (it appears), the platform the user is using (I am using Vista, it shows as WinNT), and the browser that is currently making the request to a page. Apparently, the User.Identity.Name only shows my PC name and current user locally (at least I hope), since I was doing this via VS's developer environment. Searching around at various "Privacy" websites does show some insightful information about what browsers send in GET header information though. |
||||
|
|