Clean Code Update #1

So a quick update on my Clean Code book challenge. I’m starting on chapter 5 this evening. The first four chapters covered variable naming, function naming, code commenting, and generally what is clean code. Chapter five looks to structure and format code and I’m looking forward to that. Although I have to wonder if this topic is dated as most modern IDE’s automatically structure and format code blocks, so we’ll see how it goes.

I’m really enjoying the topics and while I’m reading it I’m reflecting on code I’ve written in the past. This reflection has made me think of my programming skills and a general timeline of how much I’ve progressed in just this past year. A year ago I knew nothing about design patterns, my understanding of polymorphism was limited at best and most of my code was tightly coupled and used singleton patterns throughout. All terrible design decisions for object oriented coding.

Here’s an example of some bad code I found, while I haven’t refactored this code yet as I have bigger plans for the project that this code resides in. I think highlighting at-least some of terrible decisions I made, reinforces the topics learned in Clean Code

[code language=”objc”]

/*——————————
POPULATE BLE WITH ADV DATA
——————————-*/
-(void)populateData:(NSDictionary *)advertisement :(CBPeripheral *)peripheral :(NSNumber *)RSSI
{
NSData *rawData = [advertisement objectForKey:@"kCBAdvDataManufacturerData"];
[rawData getBytes:&myData length:sizeof(myData)];
if(myData.compId == 7057) {
NSLog(@"POPULATE DATA OBJECT");
_compId = myData.compId; // Company Identifier
_deviceName = [peripheral name]; // Device Name
_temp = myData.temperature / 100.0; // temperature divided by 100 to return xx.x format
_rampRate = myData.rampRate; // How quickly the temp is rising
_dutyFactor = myData.dutyFactor; // PLACE HOLDER
_flagStatus = myData.statusFlag; // Device Status
_speedRPM = myData.speedRpm; // Device revolutions per minute
_vibration = myData.vib; // Device Vibration
_radioStatus = myData.radioStatus; // BLE Radio status
_cycleTimer = myData.cycleTimer; // PLACE HOLDER
_batteryLevel = myData.batteryLevel; // Battery level
_currentAlarm = myData.alarms;
_macAddress = [Utility getMacAddress:myData.mac]; // Device MAC Address
_lastUpdate = [NSDate date]; // Last time the device sent an advertisement packet
NSLog(@"current alarm packet: %hu",_currentAlarm);
if([RSSI isEqual: @127]) { // Update RSSI if value is NOT 127
NSLog(@"127 BUG");
NSLog(@"RSSI: %@ RSSI PREVIOUS: %@",RSSI,rssiPrevious);
_rssi = rssiPrevious;
} else {
_rssi = RSSI;
rssiPrevious = RSSI;
}
_hasAuthorized = false;
_updateTimer = [NSTimer scheduledTimerWithTimeInterval:.5
target:self
selector:@selector(updateLastUpdateTime)
userInfo:nil
repeats:YES];
_isConnectable = [[advertisement objectForKey:CBAdvertisementDataIsConnectable] boolValue];
}
}
[/code]

If you’ve read this far and still don’t know what this code is doing, let me help. Its taking a bluetooth low energy advertisement packet, dropping it into a data structure. The code first of all takes too many arguments, as pointed out by Robert Martin, 3 arguments is too many. Code comments create excessive noise, naming convention on the method itself is obscure and not capitalized. The log statements though-out create more noise. Overall the entire code block is too loo long as well. I also dislike the constants that are defined within the method itself, for example the 7057 is a manufacturer id, what if they change their ID? this entire method would break.

Anyway, if you haven’t started reading this book yet please do. It’s very enlightening, I’m learning a ton.

I’ll see you guys tomorrow when we continue our journey down C# and discuss methods.

Happy Coding,

Corey

Clean Code

Clean code in the software development industry is hard to find, most is rushed out the door due to schedules and deadlines. I’m setting a challenge for myself. I’ll be reading Clean Code starting today. I have next week off from my CS classes so I’ll be able to pour myself into the pages and really understand the concepts Robert C Martin is projecting.

“Don’t put off until tomorrow what you can do today.”

― Benjamin Franklin

My goal with this is to understand the concepts, improve my ability to read bad code, learn the best refactoring methods, and understand the industry standards when it comes to writing good code in the first place.

I’m excited about this venture, and I challenge you to pickup a copy and post your questions and results here.

Cheers,

Corey

Start of something new

This is the start of something new, something exciting, and something I want to document and share with all of you. I’m starting a blog challenge as of today. I’ll be writing one post per day about a variety of topics. The topics will include coding tutorials, books I’m reading, life hacks about professional development, job interviews, and the work I’m doing with IOT.

Start of something new

Wait… who the hell are you and why should I read this crap?

That’s a great question, My name is Corey Canfield and I’m an average joe, I’ve been in the IT industry since 2001 when I graduated high school. I’m primarily self taught and have been working as a System Admin / Network Admin. Two years ago I wanted a change and a big one, I wanted to start developing software as a career. I’ve consumed every book, video, tutorial series I found. Now I’m enrolled in a CS degree program that I’m doing nights and weekends. While my journey here on this blog is for my benefit; to continue advancement of my knowledge by sharing what I’m doing. I’m hoping it will benefit others who might be in a similar gray area of their career and need that extra motivation to just jump in and start. So lets do this together!

My first tutorial series will be aimed at the beginner to intermediate and we’ll cover C#. Starting with the very basic IDE installation, we’ll move through variables, data types, looping, methods, decisions and much more. The reason I want to start here is I’m really excited to do a Unity 2D game development course and having a solid foundation of C# will help us through that journey.

I hope you’ll join me on my daily journey here!