The Daily Parker

Politics, Weather, Photography, and the Dog

All caught up

Two weeks ago I started writing my A-to-Z posts and got all the way to today's before my life became nuts—as I knew it would—with 4 chorus-related events and a huge increase in my work responsibilities. And with the Apollo After Hours benefit this coming Friday, this weekend will be pretty full as well.

I use my email inbox as a to-do list, and right now it has 35 messages, 30 of which relate to the benefit. I'm very glad the A-to-Z Challenge gives us Sundays off, because I don't know how I'm going to get another week ahead by tomorrow night.

The performances were worth it, though.

M is for Method

Blogging A to ZAlphabetical order doesn't actually put topics in the best sequence for learning, so we've had to wait until Day 13 of the Blogging A-to-Z challenge to talk about one of the most basic parts of an object-oriented program: methods.

A method takes a message from an object and does something with it. It's the behavior part of the behavior-plus-data pairing that orients your objects in the OO universe.

In .NET, even though you define fields, events, properties, and methods on your classes, under the hood the CLR sees only fields and methods. Properties and events are basically special flavors of methods that C# syntax makes easier to understand for humans. (See Monday's post.)

Take this simple C# snippet:

public string Name { get; internal set; }

The compiled code for that property will look almost the same as the compiled code for this pair of methods with a backing field:

public string get_Name()
{
	return _name;
}

internal void set_Name(string value)
{
	_name = value;
}

private string _name;

In fact, the method pair should look very familiar to Java developers, since that language hasn't really kept up with the times, you know? (Java developers would call the simplified version "syntactic sugar," which is what people call things that make life simpler when their salaries depend on it being complicated. It's essentially every argument a Rails developer has with her .NET counterpart until the first time she needs to decouple the database from the front end. That's when the .NET guy shows her a coding horror from the VB3 era with a mournful warning not to let this happen to her. But I digress.)

To sum up: Methods change the data or behavior of an object, but C# prefers that you use properties to change data, events to express behaviors to external consumers, and methods to ask the object to do something.

The A-to-Z challenge is off tomorrow, but it will return next week with a basic tool of organizing your software, a basic tool of performance testing, a basic principle of OO design, and three other posts I haven't thought about yet.

What happened to the brand?

Of 19 Trump-branded product lines available in 2015, only 2 remain on the market. One wonders why:

In recent weeks, only two said they are still selling Trump-branded goods. One is a Panamanian company selling Trump bed linens and home goods. The other is a Turkish companyselling Trump furniture.

Of the rest, some Trump partners quit in reaction to campaign-trail rhetoric on immigrants and Muslims. Others said their licensing agreements had expired. Others said nothing beyond confirming that they’d stopped working with Trump. Their last Trump goods are now being sold off, often at a discount: One cologne is marked down from $42 to $9.99 for an ounce.

“Success by Trump,” the website says. And below that: “Clearance.”

“A caricature of what wealth is — as opposed to what real wealth is,” said Milton Pedraza, chief executive of the Luxury Institute, a consultant to luxury brands. Trump sold to those, he said, “who didn’t know the difference,” he said.

However, Pedraza said, Trump began to undermine his own success by “label-slapping” — sticking his name on anything he could, even the farfetched and ridiculous. Emeril Lagasse sold pots. Greg Norman sold golf shirts. Trump sold. . . everything.

“There was no strategy,” Pedraza said.

Seems like a strategy that could work, depending on your audience. Good thing we Americans have strong antibodies against charlatans.

 

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.