Management 101 – Make Dashboards

Yes, I am a Manager now…  not saying where because I value my job but this is my innovation for Managers everywhere.

Make Dashboards – Upper Managers seem to love Dashboards and this is all I am gonna say about this.

And who ever said I’d have to have an MBA to be successful in Management, anyway ?!?

 

Simple improvement – 3D Pie Charts !!!  Gotta love Excel !!!

 

Advertisements

Animal Kingdom Interview Sample

This comes right from an actual Interview Question with a major Fortune 100 Company and since I passed the interview process I shall not mention any names here…

Let’s just say for grins and giggles, I was more than able to whip-up the high-level view for this code on the whiteboard but then this is such a simple problem from an OOP perspective.

See the code here.

I was told many others did not respond correctly to this same question…

The code presented here work in Python 2.5 or Python 2.7 and probably for Python 2.4 since these versions are of the same general family.

 

Python Type-Cast the Easy Way !!!

Python objects hold key and value pairs – this is what every object holds, key and value pairs.

Python objects that have a __dict__ make it easy to convert the object from one class to another simply by replacing the old object instance with another as follows:

See the attached file with a sample of how this can be done most simply. (type-cast-lessons.zip)

There are other ways to accomplish the same goals using more elaborate means however this works using less code.

What to do when your objects do not implements the magic methods required for the aforementioned code sample ?

Easy, you can use method injection as described here or here or here or here.

It also helps to use a really good Python Debugger in the form of the Wing IDE.  Stare at the debugger while debugging Python code just long enough and sooner or later you may begin to see how to accomplish goals you may find useful.

I am not recommending you try using the aforementioned code as part of any professional solutions unless  you know who will be doing a Peer Review of your code but I am saying these techniques may be useful in learning something about the object types being used as to whether or not the object types are meaningful.

The point being, you can either grouse and lament how things cannot be done or you can learn the Agile Method for getting things done…

String splits versus lists for static data ?!?

Every so often someone will ask a really interesting Python question, this is not one of those however the data seems to disagree with the opinions.

In some python code, I see this:

switch_fields = “id switch_model ip”.split()

which is surely the same as this:

switch_fields = [‘id’, ‘switch_model’, ‘ip’]

Since the intent is clearly to create a list of three items, why would someone create a string instead and invoke a string method to create a list?

My preference is for the “say what you want” side; I don’t consider myself to be a “Python Programmer”, though.

Some responses from various Python programmers…

I agree with saying what you want. I’d probably ask the author if they would ever be inclined to do the reverse, i.e. switch_field_str = ‘ ‘.join([‘id’, ‘switch_model’, ‘ip’]) to prove a point about how confusing/silly that can be.

 

     I agree, there is no logical or practical reason to have a static string that has a split performed on it every time the code is run. It is a waste of computational time.

Now for my response…

I was curious…

I had to run over 100,000 iterations to see a measurable difference…

Apart from the run-time differences one might find it easier to maintain code with static arrays loaded from string splits especially if one had to sit and type a lot of quote marks and commas… or maybe I have had far too many late night coding sessions in my past.

Thought I would share the attachment.

Seems the data does not really seem to support the opinions if the concern is computational time and performance… unless you wanted to do the string splits to list thing something close to 1,000,000 times; even 100,000 iterations is nothing you can measure let alone notice.

Eh, such is life.

More Interview Questions…

If you have 9 balls and one is heavier than the rest how to pinpoint the heavy one by using the balance only once?

Read more: http://wiki.answers.com/Q/If_you_have_9_balls_and_one_is_heavier_than_the_rest_how_to_pinpoint_the_heavy_one_by_using_the_balance_only_once#ixzz26piPvdP9

The funny thing is in almost 4 decades of writing software, either professionally or otherwise, I have yet to be asked to solve this kind of a problem by writing some software.

And “Yes” I realize this is supposed to illuminate something about the person who responds… but what difference does it makes as to whether we use the scale 2 or 3 times or 50 times – none of this has anything to do with computers other than whether or not the person who responds has ever spent any time thinking about this sort of problem.

It is still entirely possible to respond correctly to this type of logic problem and still manage to write crappy code.

It is also still possible to respond correctly to this type of logic problem and still manage to work for someone who cannot tell when he or she is asking for crappy code to be produced.

Also the correct algorithm for all problems of this type is to reduce the number of objects into 3 or fewer distinct groups and then use the scale once less than the number of groups.

If one’s job had everything to do with having to find the heaviest thing from a number of things then that person would quickly determine the fastest approach and use it – the rest is without meaning.

Also, if you think you can make assumptions with software to reduce the problem of either producing the code or testing it then by all means, assume away – assumptions draw bugs and defects – your customers will surely not know about your assumptions and they will find your defects for you – you have to hope they will continue being your customers during the process.  I would rather be overly careful than stupidly optimal any day of the week !!!

1 – Split the balls into three groups of three balls each.

2 – First use of the scale: Weigh any two groups against each other.
3 – If the groups weigh the same then the heavier ball is in the third group, otherwise it is in the group that weighs more.
4 – We now know that the heavy ball is one of three.
5 – Second use of the scale: Using the group of balls that we know contains the heavy ball, weight any two balls against each other.
6 – If one of the balls is heavier then we have our answer. If the balls weigh the same then the third ball is the heavy one and we again have our answer.

Read more: http://wiki.answers.com/Q/If_you_have_9_balls_and_one_is_heavier_than_the_rest_how_to_pinpoint_the_heavy_one_by_using_the_balance_only_once#ixzz26pi5EANN

Okay, so now I know how to solve this silly problem – does this suddenly make me a better programmer than I was before ?!?

I mean, really !!!!

BTW – this algorithm given as the acceptable response does nothing with the fact that none of the balls may be heavier since they may still all be the same weight. You can call this an edge condition, if you wish.

Built-In Unit Test !!!

This code has a built-in Unit Test

You know what…  I think this means I know how to write Unit Tests !!!

Well I wrote this one anyway – this is my story and I am sticking to it… LOL

%d bloggers like this: