What is Objective-C?
Are you familiar with this language, if not here are the cliffnotes: http://en.wikipedia.org/wiki/Objective-C
- Lightweight feature set (unlike C++)
- Lightweight during runtime. It has not interpreter or VM.
Here’s an example of what Objective-C looks like:
@interface classname : superclassname
// instance variables
- (return_type)instanceMethod1:(param1_type)param1_varName (param2_type)param2_varName;
- (return_type)instanceMethod2WithParameter:(param1_type)param1_varName andOtherParameter:param2_type)param2_varName;
I’m sure there are many ways to skin this proverbial cat, but I’ve worked on it for a bit and I feel I like this approach. It’s easy to modify, easy to follow along with and allows for some cool GUI manipulations. Well, as far as you can get with Windows Forms anyway.
Here’s a screenshot of how it looks when someone tries to act smart and corrupt our precious database!
Here’s how to do it.
Inspired by this question over on StackOverflow, I decided to finally sit down and work through a couple examples on how to override Equals and GetHashCode for a custom type.
Reasons why you would want to do this:
- You need to be able to compare between two types easily.
- You want to be able to use your custom type in a HashTable.
You’ve been there before, you need to verify if a certain item is already in the collection, but you don’t quite feel you’ve done it in the correct manner. Your inner programmer is itching somewhere and you just know there’s a better way.
Let me show you how with a simple example.
I’m still learning about Ruby and all of it’s features and instead of reading some boring reference book I decided to just find something I need and build it using Ruby.
WARNING: This has only been tested on Linux, Ubuntu specifically. Potential problems might be caused by the difference in “/” and “”. Yoinks!
Here’s an example of what my files look like:
And after running the script: