Back to Basics: AND vs. OR vs. XOR

19. August 2011

We often think of computers as working with numbers, and in the purest sense we are, but those numbers are simply 1s and 0s. Normally these bits can be grouped together to represent much larger numbers but as a developer, you'll often times need to use them as bits and you forego addition and division for "bitwise" (sometimes referred to as Logical) operations. Bitwise simply means that you're dealing with individual bits and not the number as a whole, the representation of the bits working together to make a larger number.

More...

C#, Computer Security, Design Pattern, Development, Misc

Alternative User Interfaces

3. January 2011

For decades now, the mouse, keyboard, and monitor layout has been the primary interaction with a computer, and although it has worked well for us in the past, I think it's time we start seeking out alternative interaction schemes. People have experimented with replacing the ol' mouse and keyboard ranging from multi finger touch screens to a wave of your hand. Let's take a quick look at a few of these UI schemes and take some pros and cons.

More...

Development , , , , , , , , , ,

Threads: Doing Them Right w/GUI

28. November 2010

I did an article over threads in a command line project. In a command line project, there are less complications than it's GUI alternative. Here, I hope to go into enough detail to put to rest the confusion that threads can introduce to a GUI application. The big hurdle is around the limitation that the only thread to interact with a control is the thread that created the control. In the beginning, I saw this as a silly rule, one not worthy of throwing an exception.  The more and more I use threads, the more obvious it becomes that this is less of a suggestion and more of a golden rule. So, the question begs, how do we create a thread to do something that we need a result back from? How do we get any information from a thread that's been started, such as progress, or state of operation? With callbacks, events, and the Invoke method! If we take some of the concepts I discussed in threaded CLR projects, like a payload struct, and use them here, than this will be an easy concept for you.

To start, I'll say that there is a long-named boolean variable we can set to false in the constructor of a form called "CheckForIllegalCrossThreadCalls." When set to false, is does just what you think, it will not check for illegal cross thread calls. To break down what that means, when true it will check to see if a thread tries to access a control it did not create, and when false, it will allow it. In simple applications this may be all you need, but any amount of complexity and it quickly becomes a bad idea. The problem with threads is their unpredictability. Should two threads happen to be editing the same control, things become unstable. From unintended outputs to crashing programs, it's not something you want to test, it's just better to do it right the first time, and every time. This variable, CheckForIllegalCrossThreadCalls, should remain true, by default it is.

For my little example here, the UI will consist of two progress bars and a button. Upon clicking the button, one thread starts per progress bar and they will update the progress bar they're associated with over time. This will leave the GUI thread to do nothing, at least until each thread calls their invokes. In addition to these controls, the form will have two delegates, two events, and a list of all the running threads. The events and delegates are paired. One pair is to update a progress bar, the other pair is for when a thread completes. There is also a struct to act as the payload for the threads, as defined here:

More...

Advice, C#, Development, Source Code , , ,

Android vs. iPhone: Day One Development

5. November 2010

These are exciting times! As an assignment at school, we are writing an iPhone game. It's a simple number guessing game. You know how it goes... Generate a random number, get the user's guess at the number, tell them "too high" or "too low." When the user guesses it right, you tell them how many guesses it took. It's actually one of the most boring games you can play, but it's a great beginning for learning a framework (and in the iPhone's case, a language, too). It has all the great aspects of a first app: input from the user, output to the user, and simple processing with a nice added bonus of learning how to randomly generate a number. I worked hard to do things right. I wanted it to rotate properly, stay centered, respond well to all input, the usual goals. I wanted a market worthy app, even though it'll never make it to the App Store or the Android Marketplace. All the specifications my teacher inparted on us for the iPhone app, I continued to uphold for my own Android project. I'm going to do my best to explain my experiences with both platforms. I have the same experience with both of them. About a month ago I wrote a Hello World app for each of them. School got in the way of looking into either of them deeper, until this assignment. I may seem pre-determined to be better at Android considering my Java history, but I'm accounting for it by saying that I haven't worked in java for years and that I'm currently getting three hours a week being taught iPhone dev and Obj-C. It evens out enough for me! This article will not be as much a walkthrough as it will be a comparison between my two experiences.

More...

Advice, Android, Case Study, Development, iPhone , , , , ,

Threads: Doing Them Right

8. September 2010

Threads... I'm not going to claim to be an expert at explaining all the low level happenings or all the intricate little bugs and/or features of them. I am going to be talking about good foundation code for making threads work right without worrying about races, locks, or GUI halts. First, a basic understanding of what a thread is. A thread allows for multiple lines of execution to be running in one application at the same time. You may need this for many different reasons. With only one thread, that thread is in charge of what's called the message loop. It'll listen and respond to events such as repainting the form and user interactions (clicking a button, dragging the window), if you put that thread to use doing something that takes a lot of time (say you click a button and that does a lot of network traffic or image processing), then the message loop goes unattended, this is how Windows decides if an app is "Not Responding" (when the message loop accumulates events) until it completes whatever it's doing, then it begins responding to the message loop again. With another thread, you can handle the heavy load and the original thread can continue responding to events in the message loop. This can be both a good thing and a bad thing.

There are many problems that can arise in multi-threaded application. Let's say you had an array, and in one thread you're getting element 6 in that array and in another array you're inserting an element into index 2. Different things could happen based on which thread gets there first, and it's impossible to tell which will. You can always use a lock statement to prevent data corruption due to multiple threads accessing it, but that can lead to thread locks and isn't always the easiest thing to do. Instead, design your application to be thread safe from the ground up. It's easier to hammer out the details to a thread safe app first and then implement it than it is to design a semi-working app and fix the thread issues once they've become prevalent. Defining set rules for how to be thread safe is hard. The knowledge comes with experience in many different applications.

More...

Advice, C#, Development, Source Code , , , ,

A Beginner's Article on Binding

17. August 2010

Windows Presentation Forms (WPF) brought a lot of cool features to C#. Hardware accelerated rendering, XAML backed control layout, and more versatile ways to bind your data to your controls. In WinForms there were ways to bind data base schemes to controls, but all in all it was a pain and rather limited. WPF opens up binding to almost any type. If you don't know what binding is, binding is when a particular property is "bound" to a control such that when the value changes, the control is updated, and in some cases, if the control is changed, the property is updated. I've thrown together a very basic application to help demonstrate some of the basics of binding, let me walk you through it.

More...

C#, Development, Source Code ,

Design Patterns: The Observer Pattern

9. August 2010

From Wikipedia: In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design. Design patterns can be a touchy subject. Sometimes described as "a solution seeking a problem," they can complicate projects where they have been implemented incorrectly through misunderstanding the pattern or by being applied to a situation that doesn't warrant that design pattern. With that said, take this article with a grain of salt. Don't look for a place to use it, but keep it as a tool for when a problem that may need it arises. With that disclaimer behind me, let me introduce you all to the Observer Pattern.

More...

C#, Design Pattern, Development, Source Code , , ,

Timeshift Is Now Up

1. August 2010

Timeshift, an encryption I've been working on with my friend Karl for over 5 years now, finally has a page of it's own. As it nears completion, Karl and I begin to gear up for starting a business around this algorithm, other algorithms we may develop, and potentially branching out to other concepts outside of computer security. The possibilities are endless and we're not closing any doors. Anyway, this algorithm has developed from a 256 bit encryption on up to 512, 1024, and finally graduating to 4096 bit. In addition to adding strength throughout the years, we've also decreased time. Timing how long it takes to do 100 MB\s, we started at a shameful 60+ seconds down to less than a second! That's about 150 MB\s! With the algorithm 99% done, we're approaching the point where we begin porting to other languages. Currently developed in C# .Net, plans are to rewrite the algorithm in unmanaged C++, Java, PHP, Objective-C and x86 Assembly (for the possibility of a hardware implementation). These languages ought to cover the majority of the market and allow almost any company to have this level of security in their own systems. We know there are many open source alternatives, but our goal has been to blow them out of the water and I believe we've succeeded so far. Over the next year this project is really going to take off, keep an eye out for updates.

Computer Security, Development

Uploaded New Projects

25. July 2010

I finally got around to it, three new projects for you all: Circle Library, RunOnTop, and MyMathLib! Written from scratch, these projects of mine are now available, source code and all, for you all to use or play around with.

My Circle Library is a simple set of two classes that offer similar functionality to Rectangle and RectangleF except the classes are for our perfectly round friends instead. Granting you options to tell if circles are overlapping, if one fully encircles another, or if they contain a point, these classes allow for some simple 2D collision detection. Also, and I'm not sure where this can be applied, but given two circles, you can find the Minimal Enclosing Circle which is the smallest circle that completely contains both circles. That one took me awhile, but it's working great.

I developed RunOnTop to force other programs to start and remain always on top. It's a great little utility app for Calculator, Notepad, a window of your favorite browser (Chrome!), or whatever you need. I admit it is one of my lesser tested applications, but it does what I want it to do on my setup of Windows (with UAC turned completely off). UAC may not reduce functionality of this program, but I haven't tested so I don't know. The code is based around a few methods of the WinAPI if you want to discover how low-level C# can go.

MyMathLib was a project to teach myself about interpreters and actually make one. It translates human written algebraic expressions first to Reverse Polish Notation and eventually to a final solution. It handles most, if not all, of the mathematical operations you would run across in a high school algebra/trig class.

You can find these projects on the right under Pages. Take your time and meander through the code, or just download and use them for your own personal needs. If you find you have a great use that I may not have mentioned for some of these projects,  let me know in the comments.

Development, Project

New Case Study Coming: Tower Defense!

20. July 2010

To fill up what little spare time I have, I've started a new project. Nothing ground shattering, I'm not curing cancer or solving the traveling salesman problem in O(n) or anything important like that, but who doesn't love a good Tower Defense game? My favorite TD has always been Bloons Tower Defense, and while playing it, I can't help but think about how I would do things from a development point of view on the back-end of the game. What tower designs would I come up with? How would I design the path(s) on a level? What creature/enemy/bloon design would I have crawling that path? Could I twist the game with a new rule or concept added in? Could it be made into a head to head multiplayer style game? My mind is flooded with the possibilities of what to include in the game! I'll be keeping track of my progress as I go and I'll post everything along with the end result at the same time, source code and all. I've already started developing fundamental aspects to the game. You can place points to draw a path and little dots currently crawl the path before disappearing at the final point. Exciting I know, but you have to walk before you crawl and crawl before you kill it with a tower.

This is my first Tower Defense game to ever make so we get to walk the path together when I finish writing up the whole article for you. The design process is moving along and today I plan to talk specifications with my lead art designer (my buddy Brice) about what visual themes we want to give the game, he'll definitely be in charge of that. I plan to go over details such as how I'm going to track of a path for the enemies, what strengths/weaknesses to give my towers/enemies, what choices I give the player, how difficulty settings change gameplay, the money and points systems, and every detail I can come up with down to the name of the project (currently undecided). I don't have too many things set in stone, yet. All I can promise is that it's going to be in C# and optimistically take a good two or three weeks. I'm sure you'll hear back from me before it's done, though. This is the first of many case study programs I'll be doing so don't forget to come back and check out what's available.

C#, Case Study, Development , ,