Tuesday, November 29, 2016

Making the Most of Memory

Always so much to learn. For example, did you know that the time it takes to access your computers memory is MANY times slower than the time to access the CPU caches? What does this mean for how we structure our programs and architectures? We'd want to take full advantage of the CPU Cache (L1) and the L2 cache if we are concerned at all with application performance. What this means is structuring components and code so that caches can be used.

Even if we go only to the DRAM (and not disk cache), it only holds the data for ms before having to be refreshed...this means you have under 100ms (as of the article in 2008) to process everything in memory before it cycles and has to be refreshed.

All of this has implications on the design of your objects, structs, etc. SRAM in the L2 cache is limited in memory space due to power consumption and costs. Given this, it seems logical that keeping your data bags as small in size as possible would be of great advantage to performance. Additionally, limiting loops and batches could also help to improve performance.

Architecturally speaking, since operations are also cached in the L1, you'd want to keep the same operations (looking at you data access) on the same CPU/L1. So much to learn...

Read about it in depth at https://lwn.net/Articles/250967/

Tuesday, November 15, 2016

Bugs and Defects, What Issues Really Mean

In episode 3 season 1 of Mr Robot http://m.imdb.com/title/tt4730002/ there's a highly used metaphor about bugs. The lead character's (an elite hacker) narration says that most people think finding a bug is about fixing the bug. Basically goes on to say that it's really about finding the flaw in thinking. Sounds a little like root cause analysis.

The first bug ever was called a bug because it was literally caused by a bug in a relay. Certainly not working as designed. Read more about that at http://www.computerhistory.org/tdih/September/9/

Jimmy Bogard provided a clear interpretation of what a bug is (and isn't) and how to deal with it. He and his affiliates break it down to Bugs, Defects and Stories. They "stop the line" to fix Bugs. Bugs are showstoppers, while user feedback are classified as issues. They don't believe in Bug tracking in their shop.

Think of it this way-if the first Bug ever were not removed immediately, how would that system be expected to work?

Seems to me that Bugs are mostly caused by a change in the environment which was not accounted for in the design (or a complete failure to verify implementation against acceptance criteria). Defects, on the other hand, come down to a breakdown in understanding - a Defect is when the software meets the acceptance criteria, but doesn't do what it needs to do.

There's a saying attributed to Jeffrey Palermo - "a process that produced defects is itself defective."

When Defects and Bugs creep into a system, sure we can just go ahead and fix em, move on and push on. But sometimes, and especially if this happens a lot, it's time to fix the underlying defects that are causing the Issues (Defects and Bugs). Process re-engineering, training, the environment (are we on a stable platform?), deeper analysis, etc.

That first bug ever? Perhaps that lead to a cleaner environment when running programs. Maybe it lead to innovations in storage mechanisms. Maybe it lead to nothing. Certainly, if it was a recurring problem, something would've been done.

Tuesday, November 1, 2016

A Spec File Should...

When writing a spec for an interface (public facing functions/methods of a software module/api) and that spec is written in the same language and that spec is a runnable test that executes the module...it is a fantastic way to show others how the module should work and how to use the interface...so the spec should be written in a way as it conveys these things to the reader.

Imagine a spec written for a users API. And that API has a method to getUsers and that spec has the following description:

"it should all active employees"
and the API is exercised like this:


How safe is it to assume that the first input parameter is isActive. Or could it be null? Or some other flag?

To remove ambiguity in the spec, ALWAYS pass named variables...

includeInactive = false;

yeah, yeah most editors and IDEs show the variable name somehow. Not always going to be accurate, or clear, or built yet (write the spec first anyone?).

Tuesday, October 18, 2016

Polymorphism Can Save Time and Make Code More Fun

After a day of working with some rather procedural code and shoehorning it into something a bit more OO, I've concluded that this code base would've benefitted from some SOLID OOP early on.

This code base takes a set of data in a tree-like structure and generates an html tree view based on certain attributes of each data point. The tree views are not basic like a file tree, but are based on that with more features. And it needs to display differently depending on where it's being rendered. User authorization for each data point is an additional consideration.

Reasoning about this, we can see how polymorphism can benefit us here. For instance (pun intended), the basic flow of walking the tree of data would not change, except for the fact that some business logic applies to whether a node should be added or not - could be several reasons a node would not appear in the view (e.g., security, choice, etc). Filters could be used to achieve this depending on requirements. Or a class which implements filtering. Either way we slice it, the tree of data needs to be walked.

While walking the tree, whatever is rendering the tree view can either construct it on the go, or construct/serialize in one go. For the latter choice, it can hold a collection which can be added to, or receive a collection. That collection would closely model the data tree, but with whatever visibility rules applied to it by any business logic classes.

Whatever is walking the data tree should then take in business logic as a dependency. The polymorphism part is that different types of nodes can be added to the tree view depending on the result of that business logic. I'm thinking of an interface that takes in the data and returns a TreeViewNode. TreeViewNodes are FolderNodes or FileNodes (leaf nodes). But have additional properties which control other aspects of the nodes.

Hey, sounds like we can do this better than procedural with functional programming too!

(buildview (map transformToViewDataList ( filter context dataList) )

But I digress...with OO it would have different implementations of the interface for different business cases, but the same recursion. Heck you could even have different implementations of tree recursion if needed -

nodeMapperFactory = GetFactory(context);
rootNode = GetRootNode(data);
treeWalker.WalkTree(rootNode, nodeMapperFactory);

nodeMapper = nodeMapperFactory.Get(currentDataNode);

viewNode = nodeMapper.MapNode(currentDataNode);


each(WalkTree(childNode) in children);


Monday, October 17, 2016

Quick Tip: Study OSS

OSS repositories abound. Just pick your favorite bits of open-source and study the code that makes it all go! There's a lot to be learned by studying the source code. Even more by pulling it local and running it. Make a few changes and experiment with it. Most will come with automated tests. Go ahead and make up a few of your own.

They've got all the info out there on how to get the source code locally and a bunch of other info here if you need:

Tuesday, October 11, 2016

Getting Political

This is not a political blog, it's a tech blog. However, I watched the presidential "debate" last Sunday and I'm feeling it this week. What am I feeling? I'm feeling a sense of ugh - like many who have described it as an ugly, dirty feeling. But why?

I'm trying to sort out why this feeling was put on all of us - why do we feel this way after this debate? I have reports from one coworker who's husband is a political junkie - he was ok to turn it off after five minutes. I assured her that it didn't get any better.

I want to start with the Trump campaign, since its an interesting campaign marked primarily by the strategy of making the OTHER candidates unlikable. It's a smear campaign, plain and simple. There's an unfortunate side effect to this strategy, the rest of us (meaning Americans) are getting smeared right along with the others.

With comments that allude to how bad things are, we all get dragged through the mud. Sure there are some problems...everybody's got their problems and its just nothing new. What I haven't seen is a Trump who really says "I know how to fix it". Where's the "champion for change" attitude? He has more of a blame game..."its all wrong and its their fault". A whole lot of it shameful whining, frankly.

Can't stand to see my country that I love and all of her people dragged through the mud and put down for Trump's political gain. I wanted to put a finger on that sort of negativity we've seen in the #debate and see what kind of person behaves that way. I found one article https://www.davidwolfe.com/12-traits-negative-people-avoid/
which lists out some traits such as:

They never apologize.
Blame others for their mistakes.
Hope to see others fail.
and 9 other unpleasant things.

I found these aligning right up with what we've seen from him over the years.

Then there was this blurb on pessimism https://www.psychologytoday.com/basics/pessimism
it said pessimistic people make better leaders. I do think you can't have a blindly optimistic leader, else they'd get taken by everything. But I can't help think too much pessimism makes for bad morale. And when morale is bad, people aren't going to get moving to get things done. I've played enough civilization games to know how that works - eventually cruel lords incite revolt. It takes a healthy mix of tough-but-fair to be a good leader.

Now Clinton...she's a pro politician. She's running a well-devised campaign. Giving measured answers. Skirting tough questions and always going back to her agenda - I'm more electable. Laughing off whatever is thrown at her to try to break her. Always veering back toward her agenda and away from danger. Answer the fucking question will ya...

I do believe she is playing for the certain votes, being too nice while she's at it. She did go after Trump a bit by saying he's not fit to be president. Maybe let those allegations come out in other ways a bit more. Just a bit weak on defending past actions (hers and others). Could use a bit more Joe Biden attitude...that "I've been there and done that, you peon" sort of attitude..."and another thing, you don't know shit so quit acting like you do"...you know, but without actually saying it. Now that's class!

The private email thing...makes you wonder what was there. I'm not an advocate for invasion of privacy. She was dealing with a whole lot of terrorist countries - could be national secrets, could be shady deals, could be dirty emails to and from Bill, could be campaign strategy. Don't mix work and private emails people! I hear this all the time where I work, IT tells everyone not to do this. Do people do it anyways? Yes they do. Should they? No they shouldn't.

All of this and there wasn't really much talk about the issues, of which the parties are SO polarizing on. I don't think it's sensible to push for so much polarization for political gain (pandering for votes). Nothing good will ever get done that way. But since campaigns are run on polarization, that's what we're going to have - we get a whole lot of black/white on issues that really have a whole lot of grey area. Guns, foreign affairs, personal liberties, national security, taxes, GDP, debt; all are highly complex issues and the political campaigns try to box them up as simple black and white in order to manipulate the public into voting for them.

Just take the gun issue in and of itself - fear of change, even responsible changes, to gun laws are so far polarized as infringement of rights that we can't have sensible laws in place to keep gun sales within the law.

iCan't balance a budget. Can't appoint a judge to the highest and most respected court in the world. All because of this black and white attitude the parties are using to control votes. What if you are one way on some issues and the other way on others? God forbid we should have thought for ourselves without ganging up with party polarization...we might actually find ways to solve the issues. Who gains from that and who loses?

So both candidates kind of suck. They've both made mistakes. One makes Americans and men look bad, the other has some skeletons in her closet. Either way you better believe every other candidate is shaking in their shoes hoping their own secrets aren't getting dredged up from the depths. People make mistakes, it just happens. Good people do bad things, bad people do good things. It's not all black and white. What's important is how we move forward and how we learn from past mistakes. Part of me can't wait to see what kind of crazy shit gets dredged up next, but the other part want to see a much more positive run for the White House - one with far less casualties.

Monday, September 19, 2016

Is Light Speed Travel Possible?

Off topic for a software blog, but just a quick thought - if matter can be converted into energy and reconstituted back into the exact same form of matter again (all particles arranged as they were before), then yes...that would be one way of moving mass at light-speed. Ah...providing that the form of energy could be moved at light speed. Might take a while to convert matter to energy and back again though.

It's kind of like a chicken and egg problem isn't it? What converts the energy into matter? Wouldn't the transducer need to be in position at the destination first (e.g. light-years away)? Or perhaps there is some way to remotely manipulate particles from afar in such a way that they can be rearranged into a predefined arrangement. And only the energy would be sent across. Guess that would be more or less making a copy of the matter rather than actually moving it via its energy form. Guess that would be more or less cloning matter than transporting it.

Bah, can't help myself, let's do a software thing...they say that a 64-bit number (a long) can hold a number bigger than all the atoms in the Universe times 200. And we can store those numbers all day long. How many numbers, bits, etc...would it take to store all the atoms in a frog? Assuming we had the necessary transducers to take in a signal and reconstruct the matter, what would it take to beam up a frog Scotty? Assume also that we can digitally encode matter and send it to the other side. Hint: Apply problem solving technique from last post to solve this problem.

Someone should make a GitHub project out of this...oh wait, I'm on it...here it is.