Monday, July 16, 2018

C# Logging: Where To Setup The Logger

Applications need logging. In C#, you will typically log various types of events like exceptions, debug, and informational. Your logs will contain valuable information which you'll use to tune your application and understand user behavior.

It's easiest to either pass an enum value to a single Log method or call a specific method to write different types of events. It's typical to write to different logs depending on the context. The problem is, where and how do we access the logging API from our methods?

Dependency Injection


Dependency Injection is one possible approach. If you go this route, you have to pass around a logger to all your classes as a dependency. You can use constructor injection and take the logger in as a constructor parameter. For a User class, you would pass it in along with the UserRepository as follows:


public class User
{
  private readonly IRepository<UserData> _userRepo;
  private readonly ILogger _logger;

  public User(IRepository<UserData> userRepo, ILogger logger)
  {
    _userRepo = userRepo;
    _logger = logger;
  }
}


The User class takes in the logger along with any other dependencies.

Via IoC Container

Even if you use an IoC container like Ninject or Unity, you have to add the logging interface to all the constructors and make a class member. With the IoC container approach, you can also ask the container for the implementation.

Container.Get<ILogger>()?.LogError(...);

Results and specific approach may vary according to the container, but this will at least allow you to fetch the logger whenever you need it without having to pass it around.

The .NET Core Way

In .NET Core 2.1, there are two ways to go about it as written by Luke Latham. Luke recommends using the LoggerMessage class over the LoggerExtensions for high-performance applications.

The Problem With DI

But let's suppose that you're not using core and you don't like the idea of adding the logger dependency EVERYWHERE! It isn't a dependency of the class that has anything to do with the business logic of the class. It's an implied dependency of all classes in the application. If you first design the class without the logging dependency, then you have to add it when you need to use logging.

IoC containers make this easier, but what if you have static methods from which you need to log (it happens)? In that case, you don't have constructor variables. You could pass the logger in the method params, but then you're passing around a logger. That's not a particularly elegant pattern! For one thing, you end up with more parameters. Another, you get into the habit of passing things around you may or may not need.

As Global

If it's a dependency everywhere, it's a global dependency. I don't like globals for many things. They are for configuration and that's really about it. It's beneficial to have a global logger too!

I also don't recommend statics for most things. Well, the logger could be a static global so long as it doesn't have mutable state. In other words, so long as you set the logging configuration once and leave it along throughout the entire application lifetime.

Log.LogError(...);

And in your implementation of the static method, you can get it from the container or some other global context.


public static void LogError(params object[] logParams)
{
  Container.Get<ILogger>()?.LogError(logParams);
}

This is actually a better practice since you only have to change your Log class if you change IoC containers and the interface doesn't match. It's better separation of concerns (SOC). The place to change the logging is in the Log class rather than everywhere else!

Concluding


Most of the methods discussed here are fine and dandy. I'm just not a huge of fan of having to pass things around in every class. I wouldn't extend this idea to something like a repository though, those are business logic specific dependencies that actually have meaning to the class at hand. A User class taking a UserRepository is meaningful. Every class taking an ILogger has no meaning and actually distracts from the purpose of the classes.

In sum, global is the place for the logger!

Book Review: Astrophysics for People in a Hurry

While I was shopping for a new Chromebook, Amazon recommended some books for me. One of those books was Neil deGrasse Tyson's "Astrophysics for People in a Hurry" (if you're interested, please use this affiliate link or the one at the end to purchase your copy - I'll get a bit of commission at no extra cost to you). My wife got me this book as a gift in 2017 as a matter of fact. I have to say, it was a fun read!


I've read a lot of pop-physics books over the years. I had already been exposed to most of what is in this book. Still, it was a fun read! Neil just has an entertaining personality and it shines through in the book as much as it does over audio or on TV.

Contents

Just to give you an idea of what's in this book, some of my favorite topics are:

  • Dark Matter
  • Dark Energy
  • Invisible Light


Neil starts the book at the beginning. THAT beginning. The Big-Bang. He also has a chapter called "On Being Round."

On Being Round


Well, it's not about being overweight so much as it is about being massive. As Neil says, any mass in space will experience surface tensions which force it into a round shape. Spinning objects will have a more-or-less flattened round shape. Pepper that with anecdotes about spherical cereal boxes and a whole wealth of other information and you have a pretty good idea about one of my favorite chapters in the book!

Final Thoughts

I don't want to spoil anything else for you, but let's just say there are some pretty spooky things in this book! One of the latter chapters speaks of things that will leave you awestruck! And this is why we love Neil deGrasse Tyson, isn't it! He can give us the heebie-jeebies and leave us awestruck at the same time!

If you're into this kind of thing and you want a fun, easy read by one of the best minds in the physics world, read Astrophysics for People in a Hurry! That affiliate link will take you right to the order page on Amazon so you can order it now.


Sunday, July 15, 2018

Bought a Netbook

Last night I did some comparison shopping for a new netbook. I posted the details in this blog along with some affiliate links. I figured, since I'm going to buy a netbook anyway, I might as well share the experience.

A Software Developer's Rationale for Affiliating


I'm trying the Amazon Affiliates program for this experience. There's a benefit to both of us. If I'm doing some comparison shopping, we will gain maximum advantage through re-use if you (dear reader) were in the market for a netbook. And in return, you'd be helping me out by buying your netbook through one of my affiliate links. It costs the same for you, and I get a little commish for having posted my experience here.

What I really want is to share some good things with my readers. For example, I applied to be an affiliate for PluralSight. I love their selection of training videos, and I hope that happens because I believe in what they have to offer! But, I digress.

And the Winner Is...


Getting back to the topic. I went with the ASUS Chromebook C202SA-YS04 11.6" (that's the affiliate link in case you'd like to follow suit and get a great little netbook for yourself or a loved one). It seemed like the best deal on the market. With Prime Day coming very soon, you might want to keep an eye out for a good deal on it. It really came down to having the most/best reviews in the price and spec range.

Basic Specs

Here are the primary technical specs for this model.
  1. 4 GB RAM - I'd like more, but I don't know that I would need more.
  2. 11.6-inch anti-glare LED-Lit HD monitor - I'll be using this on the train a lot and sometimes that sun shines right into the windows. Anti-glare is a huge plus!
  3. 32 GB internal storage - I wanted the extra storage, wouldn't hurt whereas running out of space would!
  4. Chrome OS - I'm giving it a try. I use a lot of their apps and services, so why not. If I don't like it at all, I'm going to see about installing a Linux distro on it. Maybe Ubuntu. Ubuntu on a netbook...yeah!
  5. 2.65 pounds - this is the main thing. I needed something lightweight because I'll be slinging it on my back. I have a lot in my pack, and the laptop is just too much to lug around.
  6. Dual processor - A lot of the less expensive netbooks have a single core processor. That means only executing one thread at a time. I prefer to have my processor multi-task so that I can keep working while background processes run. I know it depends on the app and processor architecture, but 2 cores are usually better than 1.
So those are the basic specs. And that's part of why I went with this model.

Primary Deciding Factor

It really came down to the reviews. This one had the specs I liked, and it had the most reviews and a comparable rating to other netbooks in its class. To me, this says that enough people bought it and liked it enough to give a favorable rating. Statistically, a set of over a thousand reviews is more significant than a set of under one hundred. So I went with the popular vote.

I'll post some pics when I open it and do a quick review once I get a feel for Chrome OS. Thanks for hanging with me tonight! Have a happy Prime Day!

Saturday, July 14, 2018

Buying a Chromebook

Ok, so I have a Lenovo Notebook that I use for everything right now. It's decent enough to do what I do. I'm using it right now, in fact. I can use the internet. It works for programming. Sure, it isn't a top-of-the-line model, but it's getting the job done!



Except, when I take it with me on my daily bike or train ride and it's hanging out in my backpack adding 5 or 6 pounds to the load. Then it sucks! I need something lighter. I'm considering a Chromebook but I don't know which one. Maybe it doesn't matter since they're priced so low that it's not like it would be a total loss if it wasn't that great. But then again I don't want to be so annoyed that I can't be productive. I plan to blog a lot on it and need it to be portable.

Here are a few that I have in mind (I really am buying a netbook, but I want to mention that all the links are affiliate links, so if you would like to purchase any of them I get the benefit of a commision at no cost to you...and a big thank you if you do!):

ASUS

The ASUS Chromebook C202SA-YS02 11.6" has 4GB RAM, 11.6-inch monitor, and only weighs 2.2 lbs! I like the lightweight.

But then again, it's only got a 16 GB hard drive and the next level up has a 32 GB. The ASUS Chromebook C202SA-YS04 11.6" is the same but with the bigger hard drive. Apparently, 16 GB extra of hard drive adds 0.4 lbs.

The only thing is they come in dark blue. I'm not too concerned with color so long as it's not a standout color, but I would prefer something dark-grey or black.

Samsung

I could go with a Samsung Chromebook 3 XE500C13-K03US. It has a 4-GB RAM and a 32-GB Hard Drive. And, oh look! 2.54 lbs! And what else? A Dual-Core Intel. Hmm...Samsung, should I give you a shot or keep looking? There's only one left, but I am a sucker for familiar brands. I haven't had a Samsung laptop. I know other folks have had some problems with other types of Samsung products. 4 stars for this though. Let's see what else:

Acer

This Acer Chromebook 11 is looking mighty nice in Clamshell White. Not really my taste. I would get one for my daughter though. Ok, so it does come in black too.

HP

I do have experience with HP products - mixed but generally good on the hardware side. So there's the newest HP 11.6” HD IPS Touchscreen Chromebook. Touchscreen, eh? I never really worked with a touchscreen before. I might give it a shot! It's pretty lightweight at 2.5 lbs. Says the battery will last 12 hours on average! Most of the others were around 9, so that seems pretty good! 2 processor cores - another plus. The 16 GB hard drive is a bit of a drawback.

Decisions, Decisions...

In the end, I think I'll go with the masses. That second ASUS with the 32 GB has the most reviews and a four-star rating at the moment. Seems like it would be the best all-around. It's just a little more pricey than some of the others, but you get what you pay for right?

Friday, July 13, 2018

Introducing: "SWARMing"


Hello all! I popped into Dan North's blog to see what he's been writing about lately. Dan North introduced BDD (Behavior-Driven Development) to the world which bridged a huge gap between the Customer and the Team.




His latest post "In Praise Of SWARMing" grabbed my attention. I thought it was going to be about "swarming" a problem as in Kanban. But it's actually a different-ish approach to adopting Agile at Scale. SWARMing is Scaling Without A Religious Methodology.






His ideas really hit home with some great points! There are some harsh criticisms of competing methodologies. Those are somewhat tasteful. And I have to warn you, its a bit wordy. At over 4200 words, it's quite a bit more than your average "browsing the internet" post.


Here are some things that really jumped out at me.

The Good Parts



I particularly like the contrast between "moving the work to the people" and "moving the people to the work." This translates to reorganizing. The term "self-organizing teams" comes to mind.


I do prefer the flat structure of "every part of the org is geared in delivering value" vs the slanted structure of "sales makes the money and everyone else spends it." It allows businesses to utilize all their assets in focus of value delivery.




I read once that value is expressed as the benefit for the cost. A "good value" doesn't necessarily mean inexpensive. It means you actually got a return on your investment, monetary or otherwise. I wonder if looking at your organization from a "good value" perspective would make a positive difference.


Speaking if value: There are a couple terms worth following up on. OKRs are a relatively new way to set and measure goals. I learned about Risk-Adjusted Return on Investment, which is your profit plus or minus risk.


The Bad Parts

The post is long. It has quite a few run-on sentences. The upshot is that it's not an easy read. My concerns are that you (dear reader) won't see through to the beneficial parts. Please press on, it's worth it!


You've also got to see past the sales-y aspects. He's pretty tough on competing methods of implementing Agile at scale. He's right with those points, but it drags the article and makes for a slightly bitter taste. Sorry.


I get it, he's selling consulting services and differentiating from his competitors. But that wouldn't really be necessary if the most valuable points were laid out without the cruft. Maybe do those parts in a future post dedicated to a comparison.


The last "bad part" is the focus on hard numbers. These days, organizational psychology says to keep your focus on doing good for your customers. But that depends on perspective I suppose. Those with the pocketbook will care about the revenue aspect, especially when they're being told to rethink how they allocate funds!

The Rest




Somewhere past halfway, Dan iterates over eight points about how to be SWARMing. Some of those go into depth with definitions of types of leaders: servant-leader and leader-leader. This section has some practical advice for hiring services to help with your transformation process. The successful transformation will be a long and investment-intensive road, so buckle up!

Conclusion

I sent Dan an email asking if he had a more concise description of SWARMing. One that, hopefully, lays it out without the heavy padding. Those things are valuable to support the idea, no doubt! But I can't exactly expect busy execs to read such a lengthy argument all at once. Especially when it's a new idea which asks them to rethink their organization from top-to-bottom, front-to-back, and side-to-side.


All in all, I'd say it's worth taking the time to read his post. With the right packaging SWARMing could be a catalyst for much needed change. I hope it gets that with a bow on top.





Thursday, July 5, 2018

Book Review: To Sell is Human, by Daniel Pink

I've never posted a book review on this blog, so here goes!

I've been inspired in the past by Daniel Pink when I read his bestselling book Drive, I subscribe to his newsletter, I've written him a couple emails (to which he responded). You might call me a fan. Maybe I am. I did, after all, read another of his books - To Sell Is Human.

Here are some things you might like about it (I know I did)...

What's It About?


In this book, Daniel Pink points out that we all sell. He makes a distinction between sales and non-sales selling. Sales selling is the traditional kind that makes you think of a used-car salesman from the 70's. Non-sales selling is the kind we all do - all the time!

Daniel takes you on a sales call with Norman Hall, the last remaining Fuller Brush Man. Norman is a "door-to-door" salesman. He is resilient, friendly, and has specific characteristics that make him a perfect seller. We should emulate Norman!

We go on other journeys to find out more about non-sales selling. Daniel takes us along to a training session with VPs, CEOs, and other business folks who are sharpening their selling saws. This book is packed with practical advice and results of studies to substantiate his claims.

So, Why Does Traditional Sales Suck?

The book shows us how we generally think of traditional selling in a negative light. Then it opens our eyes as to why. Spoiler Alert! The sales we think of - used car sales from years ago - is an unbalanced transaction. The sellers have all the power. That power was so often abused that the decent folk got pushed out. Why did they have all the power and what changed?

I'd recommend that you read the book and find out for yourself. But, since there are so many goodies in To Sell Is Human, I don't feel sorry about giving away this bit. The equation changes when buyers are informed. For example, we can find out everything we need to know and more about a used car before we buy. And we're not as limited in our options. We have the internet. The "information superhighway" for those of you old enough to remember the TV commercials.

Traditional sales used to suck, but it doesn't anymore. It's been transformed into more of a partnership. The role is more about discovering problems and applying solutions than it is about tricking uninformed consumers. Sure, those types of salespeople are still around feeding off the bottom. But your real sales jobs are much more elevated. Think about this...who is running the company you work for? Do they know how to sell?

How Do I Sell?

And then there's non-sales selling. You already do this. Whether you sell the dentist to your kids, a vacation to your spouse, or a new procedure to your boss you're selling! Daniel gives us plenty of practical advice we can all use in everyday life to make the sell.

He presents the new ABCs of selling (Attunement, Buoyancy, and Clarity) in an entertaining and digestible way. There's a lot to learn for those of you who have a hard time selling your ideas. There's some for those of you who think you have it all figured out too!

Besides those ABCs of how to be, he shows you what to do. Pitch, Improvise and Serve.

But, I'm an Introvert! I can't Sell...

This may come as a shocker, but extroverts aren't much better at selling than introverts! It turns out that ambiverts, those who are in the middle of the spectrum between intro- and extro-, are the best sellers. And chances are, you're more in the middle than you care to admit!

"vertedness" isn't binary any more than "brainedness" is right or left. Both are a spectrum, and most people are somewhere in the middle. Find your middle ground and become better at selling! Too much extro- leads to pushiness and not listening. Too much intro- leaves you under-assertive and too quick to walk away. Balance is better, despite what folklore says.

What Can I Take With Me?

This book is a perspective changer. It has shocking revelations! It has practical advice! It's fun to read! To use one of the techniques in the book: To Sell Is Human is a great read, you'll be pleased indeed!