The Daily Parker

Politics, Weather, Photography, and the Dog

Spring was here, momentarily

We had an absolutely beautiful day in Chicago yesterday. I ate lunch outside after going for a walk to obtain it. Birds sang. Trees started budding. The sun shone.

And then, suddenly, the sun didn't shine anymore:

Chicago lies in the transition zone between cold air to the north and mild, moist air from the Gulf of Mexico to the south, and where the boundary passes a point in its gradual southward push, the temperature drop is remarkable. On Thursday afternoon the boundary, actually a sharp cold front, pushed across downtown Chicago, and the temperature plunged from 22°C at 2:43 pm to 10°C at 2:53 pm — a 12°C drop in 10 minutes.

Yeah, that's my city. Today the weather will be gray and cool, then wet and cold tomorrow, and then Sunday we could have snow. In bloody April.

The irony? The cold weather in Chicago is actually a predicted effect of global warming. Warm polar air and a warm air mass off the east coast of North America have trapped a cold air mass over the prairie provinces and northern Quebec. The world as a whole is warmer than normal today. If you're in Europe, for example, you're having a really nice evening.

L is for LINQ

Blogging A to ZDay 12 of the Blogging A-to-Z challenge will introduce you to LINQ, another way .NET makes your life easier.

LINQ stands for Language INtegrated Query, which Microsoft describes as follows:

Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support. Furthermore, you have to learn a different query language for each type of data source: SQL databases, XML documents, various Web services, and so on. With LINQ, a query is a first-class language construct, just like classes, methods, events.

LINQ does a lot of things, so let me show just a small example. Before LINQ, if you wanted to loop through a collection and filter for specific characteristics, you'd have to do something like this:

public static ICollection<Room> ForEachLooping(IEnumerable<Room> rooms, string filter)
{
	var result = new List<Room>();
	foreach (var item in rooms)
	{
		if (filter == item.Name) result.Add(item);
	}

	return result;
}

Here's the LINQ version; see if you can spot the difference:

public static ICollection<Room> LinqLooping(IEnumerable<Room> rooms, string filter)
{
	return rooms.Where(p => p.Name == filter).ToList();
}

LINQ adds a whole set of extension methods to the IEnumerable<T> interface, including Average, Sum, Sort, Join...basically, everything you can do with a SQL statement, you can do with a LINQ statement.

In fact, there's an alternate syntax that's even more SQL-like:

public static ICollection<Room> SqlishLinq(IEnumerable<Room> rooms, string filter)
{
	return
		(from r in rooms
		where r.Name == filter
		select r)
	.ToList();
}

Note that LINQ naturally operates on and returns IEnumerable<T>, not ICollection<T>, so I invoked the .ToList() method for easier testing. In fact you would want to return IEnumerable<T> so that you can easily chain methods that use LINQ, as LINQ doesn't evaluate the whole query chain until you try to use one of its results. Calling ToList() forces an invocation.

LINQ is super-powerful and super-handy in too many cases to enumerate* in this short post. But if you use ReSharper (see Tuesday's post), you will learn it super-quickly.

(* See what I did there?)

In other Chicago news...

Eddie Lampert's reign of terror against Sears continued today when the chain announced the closing of their very last store in Chicago:

Sears, founded in Chicago and facing mounting troubles, is closing its last store in the city.

Employees at the store at Six Corners in the Old Irving Park neighborhood were told of the closure Thursday morning, spokesman Howard Riefs said in an email. The store will close in mid-July after a liquidation sale set to begin April 27. The Sears Auto Center will close in mid-May.

The store was one of 265 properties sold to Seritage Growth Properties in a 2015 sale-leaseback deal.

“For more than 120 years, Sears has called Illinois home and that is not changing,” Riefs said. “Although we are disappointed by this last store closure in Chicago, by no means does this change our commitment to our customers and presence to Chicago’s residents.”

Of course it doesn't change their commitment to Chicago; they haven't had one since 2005.

Howard, Eddie: I'm thinking of a phrase that ends with "...and the horse you rode in on."

Disappearing Midwestern accents

Edward McClelland essays on the decline of the white blue-collar Midwest, as expressed linguistically:

The “classic Chicago” accent, with its elongated vowels and its tendency to substitute “dese, dem, and dose” for “these, them, and those,” or “chree” for “three,” was the voice of the city’s white working class. “Dese, Dem, and Dose Guy,” in fact, is a term for a certain type of down-to-earth Chicagoan, usually from a white South Side neighborhood or an inner-ring suburb.

The classic accent was most widespread during the city’s industrial heyday. Blue-collar work and strong regional speech are closely connected: If you were white and graduated high school in the 1960s, you didn’t need to go to college, or even leave your neighborhood, to get a good job, and once you got that job, you didn’t have to talk to anyone outside your house, your factory, or your tavern. A regular-joe accent was a sign of masculinity and local cred, bonding forces important for the teamwork of industrial labor.

The classic Chicago accent is heard less often these days because the white working class is less numerous, and less influential, than it was in the 20th century. It has been pushed to the margins of city life, both figuratively and geographically, by white flight, multiculturalism and globalization: The accent is most prevalent in blue-collar suburbs and predominantly white neighborhoods in the northwest and southwest corners of the city, now heavily populated by city workers whose families have lived in Chicago for generations.

There’s a conception that television leveled local accents, by bringing so-called “broadcaster English” into every home. I don’t think this is true. No one watched more television than the Baby Boomers, but their accents are much stronger than those of their children, the Millennials.

What’s really killing the local accent is education and geographicmobility, which became economic necessities for young Rust Belters after the mills closed down. But as blue-collar jobs have faded, so has some of our linguistic diversity.

McClelland adapted his CityLab essay from his 2016 book How to Speak Midwestern, which is obviously now on my Amazon wish list.

K is for Key-Value Pairs

Blogging A to ZThe Blogging A-to-Z challenge continues on Day 11 with key-value pairs and simple tuples.

A tuple is a finite ordered list of elements. In mathematics, you usually see them surrounded by parentheses and delineated with commas, like so: (2, 3, 5, 8, 13).

.NET has several generic Tuple classes with 2 through 7 items in the sequence, plus a KeyValuePair<TKey, TValue> structure that is the equivalent of Tuple<T1, T2>.

I'm actually not a fan of the Tuple class, though I get why it exists. I prefer naming things what they actually are or do. If you're doing mathematics and need a 3-item tuple, use Tuple<T1, T2, T3>. But if you're doing geography and you need a terrestrial coordinate, create an actual Node<Easting, Northing, Altitude> class and use that instead. (Or just add the Inner Drive Extensible Architecture from NuGet to your project and use mine.)

You probably can't avoid the KeyValuePair<TKey, TValue> structure, however. It's coupled to the Dictionary<TKey, TValue> class, which you will probably use frequently.

Example:

#region Copyright ©2018 Inner Drive Technology

using System.Collections.Generic;

#endregion

namespace InnerDrive.DailyParkerAtoZ.WeekOne
{
	public class KeyValuePairs
	{
		public void Add(string name, Room room)
		{
			_rooms.Add(name, room);
		}

		public Room Find(string name)
		{
			return _rooms.ContainsKey(name) ? _rooms[name] : null;
		}

		public void Remove(string name)
		{
			if (_rooms.ContainsKey(name)) _rooms.Remove(name);
		}
		
		private readonly Dictionary<string, Room> _rooms = new Dictionary<string, Room>();
	}
}

Under the hood, the Dictionary<string, Room> object uses KeyValuePair<string, Room> objects to give you a list of rooms. Note that the key must be unique inside the dictionary; you can't have two rooms called "cupboard under the stairs" or it will throw an exception. Also note the safety features in the code above: the demo class won't throw an exception if you try to find or remove a room that doesn't exist. (There's a philosophical question buried in there: why should or shouldn't it throw?)

As always, download and play with the code samples for more fun and enjoyment.

Ryan hanging up his skates

House Speaker and Sophomore Class President Paul Ryan has decided he won't run for re-election this year:

The latest and most high-profile departure from Congress, he joins dozens of Republicans who have resigned or retired ahead of the 2018 midterms,according to a Congressional Casualty List. According to an NBC News count, Ryan is the 24th House Republican who has decided not to seek re-election this cycle. His departure had been rumored for months.

Back home in his Wisconsin district, there are already a slew of challengers lined up, including Democrat Randy Bryce, who boasted yesterday of strong fundraising numbers. He cheered Ryan's announcement with a joke about Republican efforts to repeal and replace Obamacare.

In Washington, Ryan's announcement moves the potential battle for House Speaker out of the shadows and gives possible contenders like House Majority Leader Kevin McCarthy, R-Calif., House Majority Whip Steve Scalise, R-La., and others time to gather support for possible bids to lead their conference in the next Congress.

Jennifer Rubin sees another rat (in her own party, take note) leaving the sinking ship:

The political reality is less noble. One can hardly imagine a more obvious signal that Ryan fears the prospect, if not of losing his own seat, than of losing the majority and hence his speakership. In the past, speakers — understanding the demoralizing impact that premature white-flag-waving would have on their troops — had the good sense to wait until after the election to announce that they would exit the leadership of their party. Ryan’s move has several consequences.

First, Democrats (who were heavily spending to defeat Ryan) can declare victory in that race and save the money it would have taken to knock out a sitting speaker.

Second, this is a flashing light to donors and candidates on both sides. For Republican money-men, the message is: Don’t throw away cash trying to save the House. (One wonders whether Ryan, previously a strong fundraiser, will still be able to get donors to open their wallets when he’s abandoning ship.)

Third, this will be seen in some quarters as a sign that Ryan cannot bear defending the president from potential impeachment. It has been a chore to act as Trump’s lead apologist, ignoring Trump’s outbursts and justifying his zigzags.

I'm very much looking forward to a Democratic 116th Congress. Apparently so is Paul Ryan.

J is for JetBrains

Blogging A to ZFor day 10 of the Blogging A-to-Z challenge, I'd like to give a shout out to a Czech company that has made my life so much easier over the past five years: JetBrains.

Specifically, their flagship .NET accelerator tool ReSharper makes .NET development so much easier I can't even remember life without it. (If you've downloaded the code samples for this challenge, you may have seen either in the code or in the Git log references to ReSharper, usually when I turned off an inspection for a line or two.)

I'm just going to quote them at length on what the product does:

Code quality analysis

On-the-fly code quality analysis is available in C#, VB.NET, XAML, ASP.NET, JavaScript, TypeScript, CSS, HTML, and XML. ReSharper will let you know if your code can be improved and suggest automatic quick-fixes.

Code editing helpers

Multiple code editing helpers are available, such as extended IntelliSense, hundreds of instant code transformations, auto-importing namespaces, rearranging code and displaying documentation.

Code generation

You don't have to write properties, overloads, implementations, and comparers by hand: use code generation actions to handle boilerplate code faster.

Eliminate errors and code smells

Instant fixes help eliminate errors and code smells. Not only does ReSharper warn you when there are problems in your code but it provides quick-fixes to solve them automatically.

Safely change your code base

Apply solution-wide refactorings orsmaller code transformations to safely change your code base. Whether you need to revitalize legacy code or put your project structure in order, you can lean on ReSharper.

Compliance to coding standards

Use code formatting and cleanup to get rid of unused code and ensure compliance to coding standards.

Instantly traverse your entire solution

Navigation features help you instantly traverse your entire solution. You can jump to any file, type, or member in your code base in no time, or navigate from a specific symbol to its usages, base and derived symbols, or implementations.

I can't endorse this product strongly enough. Use ReSharper whenever you're using Visual Studio. It's worth it.

I is for Interface

Blogging A to ZDay 9 of the Blogging A-to-Z challenge brings up one of the key concepts in object-oriented design: the interface.

In object-oriented design, rule #1 is "program to interfaces, not to implementation." In other words, when interacting with an object in your system, you should care about what behaviors and data you need to use, not what the object actually does with them.

Going back to last week's room-and-window example: the original problem was that I want to close all the windows in the house with one method call. The solution on Saturday involved having a Room class that exposed a list of Window objects which you could iterate over and call the Close() method on each.

That's great, but what if I want to close all the windows, doors, fireplaces, and anything else that I can close, because of the zombie apocalypse? In Saturday's implementation, I need to know that rooms have windows, doors, fireplaces, and other things specifically. That is, I need to know how each room is implemented.

I really don't care whether the thing is a window, a door, or a squirrel's mouth; I want it closed now, before the zombies get in.

So let's do this instead: define the behavior of a thing that I can close, and operate on the behavior rather than the thing itself. In C#, I can define an interface, which would look like this (and refer back to Saturday or the code sample file for the rest of the implementation):

namespace InnerDrive.DailyParkerAtoZ.WeekOne
{
    public interface ICloseable
    {
	    void Close();
    }
}

That defines a single behavior that a class can do. (Interfaces can also define data and events, but that's beyond the scope of this post.)

Now I can add the interface to the Window class:

public class Window : ICloseable
{
	public void Close() { }
	public void Open() { }
}

And then refactor the Room class so that you can add and close all manner of closeable things:

public class Room
{
	public void Add(ICloseable closeable)
	{
		_closeableThings.Add(closeable);
	}

	public void CloseEverything()
	{
		foreach (var thing in _closeableThings)
		{
			thing.Close();
		}
	}

	public IEnumerable<ICloseable> Windows => 
		new List<ICloseable>(_closeableThings.Where(p => p is Window));

	private readonly List<ICloseable> _closeableThings = new List<ICloseable>();
}

Well, that looks different. Instead of adding windows to a room, I can now add anything that can be closed. And because of that, at lines 16 and 17, in order to make sure the Windows list still works, I have to change the code so it only returns windows.

It's still a dumb piece of code, but you can start to see how powerful interfaces are. If in the future I create some new class with a Close() method, I can apply the ICloseable interface to it and stick it in a room. (Books, maybe? Escrow accounts? People named Glenn?)

There are many, many implications to all of this. But this is one of the foundations of OO design. I don't care what the thing is, I care what it does or knows. Program to interfaces, not to implementations.

Congratulations, Senator!

For the first time in the institution's 229 years, a sitting U.S. Senator—from my own state, no less—has given birth:

Sen. Tammy Duckworth (D-Ill.) gave birth Monday to a baby girl, the first time a sitting senator has delivered a child and one of just 10 female lawmakers to bear a child while serving in Congress.

Duckworth, 50, and her husband, Bryan Bowlsbey, named their daughter Maile Pearl Bowlsbey after Bowlsbey’s great aunt. Pearl Bowlseby Johnson was an Army nurse during World War II. Duckworth is a double amputee from her service in the Iraq War as an Army helicopter pilot, getting shot down in 2006. The senator said that she and her husband consulted with former senator Daniel K. Akaka of Hawaii, who died last week, about the choice of name, just as they did with the birth of their first daughter, Abigail, four years ago.

Wait, she's 50? Wow. I can't decide which is more impressive, her age or her first-ever record. Either way, it's pretty cool.

Happy February 68th!

It's the 99th day of 2018, and I'm looking out my office window at 25 mm of snow on the ground. It was -7°C on Saturday and -6°C last night. This isn't April; it's February. Come on, Chicago.

The Cubs' home opener originally scheduled for today will be played tomorrow. This is the second time in my memory that the home opener got snowed out. I didn't have tickets to today's game, but I did have tickets to the game on 15 April 1994, which also got snowed out.

(Cubs official photo.)

Because it's Chicago. (Actually, there's a blocking mass of warm air to the east of us causing a bulge in the polar jet stream and pushing cool Canadian air down into the U.S. That sort of thing feels really nice in July; not so much in April.)