Friday, July 21, 2017
On software development and discovery
Excellent article about software development: http://www.developerdotstar.com/mag/articles/reeves_design.html
Monday, June 6, 2016
Thinking about abstractions
Begin by coding abstractions for the concepts of your application before you write the application itself.
When writing a Object Oriented program, your unit of abstraction is an object. This is important, although fairly straightforward. On every paradigm, what rules it is its unit of abstraction: on procedural languages, the abstraction is a procedure; on functional languages, the main abstraction are functions; And, if I may say, on LISP-style languages, the main abstraction are lists.
Abstraction are very important to computer development. A computer is made of such, otherwise, it would be impossible to deal with all the complexity that it englobes. It's something very particular to the field of Software Development. A civil engineer thinks of bricks and mortar. A doctor does think about cells, organs, and other basic stuff that make up our body. (of course, a quark is the most non-abstract way for thinking about anything, and if a doctor thinks of organs, he's not thinking of cells individually -- still, organs abstract over very little when thinking about a living organism).
A computer is simply a machine that runs instructions written on a memory one-by-one, so it's formed by three basic components, the memory which is a "string" of bytes, a program counter that points to a location at this memory, and the CPU which executes the instruction at the location where the program counter is pointing to. Given this, we could program anything ever, but the complexity would be unmanageable.
So we come up with abstractions. Instead of memory locations, we have variables, pointers maybe or references. Instead of a program counter, we have lines on a text editor.
Back to OOP, as soon as you can realize a abstraction is part of your program, you should create a class for it. No abstraction is smaller than a class in OOP; A bunch of methods loose within some other class aren't. However, you can build abstractions from other abstractions, so objects can be made of other objects.
An example: let's abstract over a INI file:
Let me rephrase all that:
When designing your abstractions an important factor to consider is coupling. Whenever an abstraction depends (uses!) another, it's coupled to it. So when the depended abstraction changes, the depending abstraction also changes. So it's important to reduce your dependency graph on your abstractions. The most common abstractions should depend on nothing but frameworks libs, which are your building blocks.
(however, coupling is, ultimately, inevitable; our responsibility is to make our couplings loose instead of tight)
Finally, abstractions can backfire. Abstract too much and your program gets difficult to understand. Also, you may create a lot of couplings that, loose or not, make your program difficult to evolve and maintain.
When writing a Object Oriented program, your unit of abstraction is an object. This is important, although fairly straightforward. On every paradigm, what rules it is its unit of abstraction: on procedural languages, the abstraction is a procedure; on functional languages, the main abstraction are functions; And, if I may say, on LISP-style languages, the main abstraction are lists.
Abstraction are very important to computer development. A computer is made of such, otherwise, it would be impossible to deal with all the complexity that it englobes. It's something very particular to the field of Software Development. A civil engineer thinks of bricks and mortar. A doctor does think about cells, organs, and other basic stuff that make up our body. (of course, a quark is the most non-abstract way for thinking about anything, and if a doctor thinks of organs, he's not thinking of cells individually -- still, organs abstract over very little when thinking about a living organism).
A computer is simply a machine that runs instructions written on a memory one-by-one, so it's formed by three basic components, the memory which is a "string" of bytes, a program counter that points to a location at this memory, and the CPU which executes the instruction at the location where the program counter is pointing to. Given this, we could program anything ever, but the complexity would be unmanageable.
So we come up with abstractions. Instead of memory locations, we have variables, pointers maybe or references. Instead of a program counter, we have lines on a text editor.
Back to OOP, as soon as you can realize a abstraction is part of your program, you should create a class for it. No abstraction is smaller than a class in OOP; A bunch of methods loose within some other class aren't. However, you can build abstractions from other abstractions, so objects can be made of other objects.
An example: let's abstract over a INI file:
class IniFile
{
public IniFile(string fileName)
{
// ... open a stream, and read the file if it exits
}
public string Get(string keyName)
{
// returns a value based on the key or null
}
public string Put(string keyName, string value)
{
// Store a key/value pair
}
public void Save()
{
// Write the file back to the disk
}
}
Now, this is a simple example; We can build a better abstraction than that using other language features, but it doesn't matter. The main benefit of the abstraction has been leveraged: clients of this code don't have to think about how the IniFile works:
class Configurator
{ private const string _properties = @".\config.ini"; public Configuration GetConfiguration() { var ini = new IniFile(_properties); var url = ini.Get("URL"); return new Configuration { Url = url; } } }
Let me rephrase all that:
The main benefit of using proper abstractions is that you can focus your thoughts. When coding the abstraction itself, you do not need to consider the rest of the application, only the abstraction (the IniFile above cares not if it's part of a Instant Messaging app, a game, or a scientific experiment). When coding the clients of the abstraction, you do not need to care how it works internally -- abstractions are opaque -- so you can focus on whatever the client needs to do.If for some reason your clients have to look inside your abstraction, violating it's principle, we have a leak abstraction and it should be reviewed.
When designing your abstractions an important factor to consider is coupling. Whenever an abstraction depends (uses!) another, it's coupled to it. So when the depended abstraction changes, the depending abstraction also changes. So it's important to reduce your dependency graph on your abstractions. The most common abstractions should depend on nothing but frameworks libs, which are your building blocks.
(however, coupling is, ultimately, inevitable; our responsibility is to make our couplings loose instead of tight)
Finally, abstractions can backfire. Abstract too much and your program gets difficult to understand. Also, you may create a lot of couplings that, loose or not, make your program difficult to evolve and maintain.
Wednesday, December 30, 2015
Is it possible to instantiate an object from a generic parameter in Java?
No.
The reason I’m posting this is because this question has been asked many, many, many times… and a few more.
And the answer is usually this:
Now, in c# is rather trivial to do:
Footnotes
The reason I’m posting this is because this question has been asked many, many, many times… and a few more.
And the answer is usually this:
You'll need an instance of the class. The generic type T isn't enough. So you'll do:Which lacks the straght no. While the answer above may lead a reader such as myself to believe that you can work around and use Class<T>, this is wrong. Class<T> is a type declaration, but you’ll still need a instance of it to be able to call newInstance.
class Server <T extends RequestHandler> { Class<T> clazz; public Server(Class<T> clazz) { this.clazz = clazz; } private T newRequest() { return clazz.newInstance(); } }
Now, in c# is rather trivial to do:
And, as my long time readers¹ will know, I’m a C# guy. And being that, I expected to be able to do the same in Java. Now, why isn’t it possible? See, Java doesn’t really have generics… It’s implementation of generics is all done in the compiler instead of in the JVM. And this being the case, generic type information isn’t compiled to bytecode (the only answer in StackOverflow I found mentioned it was this one), and exists only during compile time. This is called Type Erasure. Now, Oracle sells it as a good thing (I disagree, of course).class Foo<T> where T : new {private T getInstance() { return Activator.CreateInstance(typeof(T)); }}
Footnotes
1. As is “nobody”.
Thursday, October 8, 2015
The Cook
Robert "Uncle Bob" C. Martin, in his singular book "Agile Software Development, Principles, Patterns, and Practices" (Amazon), compares refactoring to cleaning a dirty kitchen. The more I think of it, the more I believe its a wonderful analogy for our work.
Analogies, abstractions and metaphors are important, as they help us understand and explain concepts more easily; most of our knowledge is built upon previous knowledge. When the subject is something as abstract as software development, it's even more important to have a concrete example to reason about.
I was used to compare developing software to building houses. It's very easy to reason about the task of house building. Most people have seem a house being built; it's partly art, partly technical; you design first (the blueprint), then you build it. Heck, the term Design Patterns came from the field of architecture. But there were are many failures in the comparison! As one of my managers once put it, one can predict exactly how many bricks¹ it'll be necessary to build the house. But we can't predict how many lines of code, classes, etc. are going to be necessary to create a software: the buildings' blueprint is definite, but no design for a software is, up until you write the code².
Now, let's think about the activy of a cooking. It helps that I don't know much about it - my cooking skills are limited to scrambled eggs, grilled steaks and anything a microwave oven can offer - so I can talk about it as the next guy.
And like cooking, it's best we know what we are doing or we may end up ordering delivery.
Analogies, abstractions and metaphors are important, as they help us understand and explain concepts more easily; most of our knowledge is built upon previous knowledge. When the subject is something as abstract as software development, it's even more important to have a concrete example to reason about.
I was used to compare developing software to building houses. It's very easy to reason about the task of house building. Most people have seem a house being built; it's partly art, partly technical; you design first (the blueprint), then you build it. Heck, the term Design Patterns came from the field of architecture. But there were are many failures in the comparison! As one of my managers once put it, one can predict exactly how many bricks¹ it'll be necessary to build the house. But we can't predict how many lines of code, classes, etc. are going to be necessary to create a software: the buildings' blueprint is definite, but no design for a software is, up until you write the code².
Now, let's think about the activy of a cooking. It helps that I don't know much about it - my cooking skills are limited to scrambled eggs, grilled steaks and anything a microwave oven can offer - so I can talk about it as the next guy.
- When cooking, there are many ways of doing the same thing: you have recipes for doing most stuff, but you can mix and match... You can replace ingredients, you can change procedure... Times can vary, so maybe you will heat the oven for 10 minutes instead of 8... As with writing software, there is always a myriad ways of reaching the same result.
- Techniques abound.
- You don't need a college degree for doing it, but specialized education exists and helps.
- Results are not guaranteed to be the same - you can do the same dish twice, and get very different flavors. And that doesn't mean screwing it up!
- Accidents may happen (this is true of any profession, but let's highlight it here, lest we forget).
- While you cook, you are getting stuff dirty. Later on, to keep on using the kitchen, you must clean this up. This means that while you can get a dish done in less time, you'll pay for it when doing your next dish.
And like cooking, it's best we know what we are doing or we may end up ordering delivery.
Footnotes
- Houses here in Brazil are made of bricks. Don't ask me why.
- I happen to agree with Jack W. Reeves that code is design. But most people don't get it yet, so, let's go with the idea that a class diagram or something is the last stage of design and code is building.
Friday, July 24, 2015
A bookmarklet to open a entity by Guid in Dynamics CRM
So I colleague of mine passed me a number of CRM 2013 bookmarklets that do all sorts of things, like showing the guid of the entity, enabling all fields, removing the business required attribute, etc. The 'god mode' one is the most fun.
Anyway, I decided to write one of mine: a bookmarklet that enables you to open an entity using it's guid. Unfortunately, right now, I ask that you also give me the entity name, but other than that, it's pretty useful while debugging applications that make extensive use of the SDK.
So, without any more delays: get it here.
If you are curious, you can check the bookmarklet code below.
Here's the same code block in a more readable way:
Anyway, I decided to write one of mine: a bookmarklet that enables you to open an entity using it's guid. Unfortunately, right now, I ask that you also give me the entity name, but other than that, it's pretty useful while debugging applications that make extensive use of the SDK.
So, without any more delays: get it here.
If you are curious, you can check the bookmarklet code below.
javascript:var entity = window.prompt("Enter the name of the entity to open the default form for:", "");var guid = window.prompt("Enter the guid of the entity to open thedefault form for:", "");var o = new Object(); o.uri = "main.aspx?etn=" + entity + "&pagetype=entityrecord&id=%7B" + guid + "%7D";window.top.document.getElementById("navBar").control.raiseNavigateRequest(o);
Here's the same code block in a more readable way:
javascript:
var entity = window.prompt("Enter the name of the entity to open the default form for:", "");
var guid = window.prompt("Enter the guid of the entity to open thedefault form for:", "");
var o = new Object();
o.uri = "main.aspx?etn=" + entity + "&pagetype=entityrecord&id=%7B" + guid + "%7D";
window.top.document.getElementById("navBar").control.raiseNavigateRequest(o);
Tuesday, July 7, 2015
USD: Default Actions In Hosted Controls
While I don't find time to do a proper introduction over Unified Service Desk, Microsoft's platform for the development of call center systems, I'll keep bringing some nice-to-know-facts about it.
Custom Hosted Controls
A custom hosted control is basically a WPF UserControl specialized to wire-up against USD's internal engines. To develop it, you can download and install the UII SDK and the Visual Studio Extension that contains the templates for it. Or you can do it the hardcode way, which I prefer, and simply install a USD nuget:
Nice! Now you can start developing you own USD control.
Actions and Action Calls
There are only two reasons to actually create DynamicsBaseHostedControl controls. One is to access the USD Context, the other is to wire up Actions and Events.
Microsoft's documentation over Action and Events is surprisingly good, so it's worth to check out. But it fails to talk about how to develop using action and events. I'll probably address this more comprehensively in the coming posts, but, for now, let's just focus on how to create custom actions that you can call from other controls.
In your DynamicsBaseHostedControl, override the method DoAction:
The args contain everything you should need to implement that call:
Now, the call to base.DoAction is very important: every DynamicsBaseHostedControl implements a few standard actions. Microsoft documentation on this is very thin (as is on everything USD), but at least these actions are implemented:
Custom Hosted Controls
A custom hosted control is basically a WPF UserControl specialized to wire-up against USD's internal engines. To develop it, you can download and install the UII SDK and the Visual Studio Extension that contains the templates for it. Or you can do it the hardcode way, which I prefer, and simply install a USD nuget:
PM > Install-Package Microsoft.CrmSdk.USD.CoreAssembliesOnce that's done, simply create a new WPF UserControl and change it's base class to DynamicsBaseHostedControl:
< dynamics:dynamicsbasehostedcontrol x:class="MyLib.Controls.Views.FooView"
xmlns:dynamics="clr-namespace:Microsoft.Crm.UnifiedServiceDesk.Dynamics;assembly=Microsoft.Crm.UnifiedServiceDesk.Dynamics"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
Nice! Now you can start developing you own USD control.
Actions and Action Calls
There are only two reasons to actually create DynamicsBaseHostedControl controls. One is to access the USD Context, the other is to wire up Actions and Events.
Microsoft's documentation over Action and Events is surprisingly good, so it's worth to check out. But it fails to talk about how to develop using action and events. I'll probably address this more comprehensively in the coming posts, but, for now, let's just focus on how to create custom actions that you can call from other controls.
In your DynamicsBaseHostedControl, override the method DoAction:
protected override void DoAction(RequestActionEventArgs args)
{
switch (args.Action)
{
case "ActionName":
DoSomething();
break;
case "AnotherAction":
DoSomethingElse();
break;
// (...)
}
base.DoAction(args);
}
The args contain everything you should need to implement that call:
- Its property Action contains the name of the action that was called. You should switch on it.
- Its property Data contains the parameters that were sent with the action call.
[as you can see from above, USD unfortunately suffers from String Obsession (a common kind of Primitive Obsession), since it's heavily based on parametrization]
Now, the call to base.DoAction is very important: every DynamicsBaseHostedControl implements a few standard actions. Microsoft documentation on this is very thin (as is on everything USD), but at least these actions are implemented:
- new
- new_crm_page
- open
- open_crm_page
- popup
- close
- fireevent
- movetopanel
- setsize
Friday, June 26, 2015
Sometimes a Gem: How to investigate/debug Microsoft Fakes build error
So I was having a d@%n issue with VS2015, which was refusing to create a fake stub for me, with the not-helpful-at-all error "failed to generate stub type for type (...)". Nothing in the build output log, nothing anywhere to explain what was going on.
Google has never been so unhelpful, which is to say, he helped me only at the fourth or fifth entry.
This post includes a gem:
It worked like a charm. Thanks David!
Google has never been so unhelpful, which is to say, he helped me only at the fourth or fifth entry.
This post includes a gem:
To debug the build issue, open the assembly.fake xml file in the Fakes folder added automatically to your project. Add the two parameters Diagnostic=”true” Verbosity=”Noisy” to the fake element, like this:(...)
Then in Tools|Options under Projects and Solutions|Build and Run, change the MSBuild project output verbosity to ‘Diagnostic’. Build again and in the generated output, look for Task “GenerateFakes”
It worked like a charm. Thanks David!
Tuesday, June 16, 2015
Name a file or folder with a starting dot
So, in linux hidden folders and files begin with a dot. In windows, it was considered forbidden to create such files (at least I believed it so in FAT32), but now you can see a number of tools creating file system entries with that naming scheme (git, for instance). But, as a user, can I name anything like that?
Well, Windows think we didn't typed a name. That's scary, we did! Or, maybe not? For Windows, it seems, everything after the dot is considered an extension, so, in this case, we just provided an extension for the file (not a name).
To go around this issue, you have to make windows understand that ".dotstarted" is the name, not the extension. And what is the extension in this case, you may ask? The empty string, of course. So, the full name, with the extension, would be...
We just specified the empty string as the extension, making sure Windows understands the ".dotstarted" part as the name. This results on it being correctly created, be it a directory or a simple file.
Let's try to create a folder that is dot-starting:
![]() |
| Sexy naming |
The result is not what we wanted:
Type a filename, it says. We just did, dummy!
Well, Windows think we didn't typed a name. That's scary, we did! Or, maybe not? For Windows, it seems, everything after the dot is considered an extension, so, in this case, we just provided an extension for the file (not a name).
To go around this issue, you have to make windows understand that ".dotstarted" is the name, not the extension. And what is the extension in this case, you may ask? The empty string, of course. So, the full name, with the extension, would be...
![]() |
| File with extensions |
We just specified the empty string as the extension, making sure Windows understands the ".dotstarted" part as the name. This results on it being correctly created, be it a directory or a simple file.
Sunday, May 17, 2015
Remove All Nugets From All Projects
This may never be used in your usual conditions, however, I found it to be useful at least once: NuGet packages got messed up after some merges, with different versions in different projects. So I wrote a one-liner to remove all the packages from all the projects in the solution.
All you have to do is paste this snippet into the Package Manager Console.
All thanks to this reference.
All you have to do is paste this snippet into the Package Manager Console.
Get-Project -All | %{ $projectName = $_.ProjectName; foreach($package in Get-Package -ProjectName $projectName) { Uninstall-Package -ProjectName $projectName -Id $package.Id -Force }}All thanks to this reference.
Monday, April 27, 2015
Let's ask together for better Visual Studio support for Git
Ugh, three times already! I'm using Visual Studio with Git and for the third time I've pushed some changes at work, only to pull those at home and find out that a few files are missing from the repo. What is that?
When Microsoft announced that Visual Studio would support Git and, what's more, Visual Studio Online (their "cloud" TFS, not Visual Studio) would have Git as well as the old, SourceSafe engine, I was thrilled. What a wonder: the magic tooling that only Microsoft is ever able to give us, and a modern repository, and a distributed one at that.
About two years later and I finally did a deep dive on that support and I must say, I'm pretty disappointed. I always thought the interface clumsy and, in the past, I reverted to using SourceTree, which is still my favorite Git client. But right now I'm working on a client environment and I have no choice but to use their machine. And this also means not being able to install anything, which means - you guessed! - using only Visual Studio support for this.
Now, besides the clumsy interface, I've realized that the support is incomplete, missing a number of features from Git, and even worse, the bad support can lead to mistakes as the one on the first paragraph:
When Microsoft announced that Visual Studio would support Git and, what's more, Visual Studio Online (their "cloud" TFS, not Visual Studio) would have Git as well as the old, SourceSafe engine, I was thrilled. What a wonder: the magic tooling that only Microsoft is ever able to give us, and a modern repository, and a distributed one at that.
About two years later and I finally did a deep dive on that support and I must say, I'm pretty disappointed. I always thought the interface clumsy and, in the past, I reverted to using SourceTree, which is still my favorite Git client. But right now I'm working on a client environment and I have no choice but to use their machine. And this also means not being able to install anything, which means - you guessed! - using only Visual Studio support for this.
Now, besides the clumsy interface, I've realized that the support is incomplete, missing a number of features from Git, and even worse, the bad support can lead to mistakes as the one on the first paragraph:
- Visual Studio allows committing with untracked files. This is my major peeve, as you all can see in the first paragraph. SourceTree simply enforces that either we ignore or push the file. I think it makes a lot of sense, and avoid problems such as the one I suffered.
- Better history view. Checking a file history through Visual Studio is doable, but not fine. I know that this isn't something easy to do through Git's command line as well, but VS can do better.
- Better Navigation. Oh my god! Clicking a dropdown to choose whether I want to see changes, branches or whatever... I think this can be much improved. Why do we have to have a small screen with the complex navigation, when we can have a full screen like a real tool? Yeah, that would break VS look 'n feel, but what of it? What is more important?
I'll keep myself to those three points. There are other places where it could be better, of course, but those three would make me very happy.
Monday, December 22, 2014
Embedding DLL's
I've faced this problem before, and ended up with the same solution: I have to deploy a solution that is composed of more than one file, usually an exe and a set of DLL's.
But the deployment process expects only a single file. With Java, this is simple; Maven can pack every dependency together and a single jar file is generated for your application. But how we solve this with .NET and it's multiple DLL nature?
MSFT Research created a tool for that, called ILMerge.
However, this tool has shortcomings, such as it's unability to work with WPF. Now, what I've done in the past (when I needed to include a native DLL to do some interop, actually) is much more like the solution presented here. In short, all you do is embed the DLL's as resources in your main assembly (be it a executable or library), and add an event handler to the AssemblyResolve property of the current appdomain
This will result in the appdomain loading the embedded DLL as resources. The code above can be adapted to even load executables if necessary.
But the deployment process expects only a single file. With Java, this is simple; Maven can pack every dependency together and a single jar file is generated for your application. But how we solve this with .NET and it's multiple DLL nature?
MSFT Research created a tool for that, called ILMerge.
However, this tool has shortcomings, such as it's unability to work with WPF. Now, what I've done in the past (when I needed to include a native DLL to do some interop, actually) is much more like the solution presented here. In short, all you do is embed the DLL's as resources in your main assembly (be it a executable or library), and add an event handler to the AssemblyResolve property of the current appdomain
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
String resourceName = "AssemblyLoadingAndReflection." + new AssemblyName(args.Name).Name + ".dll";
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
{
Byte[] assemblyData = new Byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return Assembly.Load(assemblyData);
}
}
This will result in the appdomain loading the embedded DLL as resources. The code above can be adapted to even load executables if necessary.
Monday, July 14, 2014
Linux “Touch” in Windows
Another quick reference:
The command above will “touch” a file (change its modified time).
Hope it’s useful.
copy /b filename.ext +,,
The command above will “touch” a file (change its modified time).
Hope it’s useful.
Monday, April 14, 2014
Kill a pending session on Oracle
I'm no DBA... so sometimes the simplest thing may be hard. I'm currently using Oracle in one of my projects, and I been having trouble with pending sessions / transactions. So I had to discover how to kill them. I found this link, which I reproduce partially here for the sake of preserving the information.
Identifying the locks:
Killing the session:
The SID and the SERIAL# fields can then be used to issue the kill command:
Identifying the locks:
SELECT l.inst_id, SUBSTR(l.oracle_username,1,8) ora_user, SUBSTR(l.session_id,1,3) sid, S.serial#, SUBSTR(o.owner||'.'||o.OBJECT_NAME,1,40) object, p.spid os_pid, DECODE(l.locked_mode, 0,'NONE', 1,'NULL', 2,'ROW SHARE', 3,'ROW EXCLUSIVE', 4,'SHARE', 5,'SHARE ROW EXCLUSIVE', 6,'EXCLUSIVE', NULL) lock_mode FROM sys.gv_$locked_object l, dba_objects o, sys.gv_$session s, sys.gv_$process p WHERE l.OBJECT_ID = O.OBJECT_ID AND l.inst_id = s.inst_id AND l.session_id = s.sid AND s.inst_id = p.inst_id AND s.paddr = p.addr(+) ORDER BY l.inst_id
Killing the session:
The SID and the SERIAL# fields can then be used to issue the kill command:
ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE
Thursday, December 5, 2013
Correctly Interpret Data And Statistics
A small detour from my usual subjects...
A common statistic came into my mind today. "Most car accidents happens near the driver's home". Sorry that I do not have a link to this statistic, but in my country that has been said more than once.
It has led people to believe that we are usually more careless or distracted when driving near our homes. Maybe because we are in a hurry, anxious to get to our beloved house and people, or because we are just leaving, not yet fully connected to the action of driving.
I beg to differ; I think this is a misinterpretation of the data. Let's think about it: when you go to work, what streets do you necessarily take? At least the one in front of your home (if you have more than one exit, well, you are blessed, aren't ya? But follow the thought). When going to the supermarket, the mall, a concert, your parent's house, etc., what streets are common in those trajectories? The ones around your home, of course! At the end and beginning of almost every day you are driving around your home.
So, let's assume for a second something more, well, conservative. That the probability of having a car accident on any given street is the same, at least on average. Now, since you are driving near your home much more than you are driving anywhere else, indeed, the probability of an accident in this vicinity is higher!
I'm not saying that distraction may not be a factor here. Those two conclusions are almost equivalent. I'd say that mine seems a little more fundamented of factual, consistent affirmations (since I'd not had to infer that people were distracted), but in any case, if there are at least two reasonable explanations to this data, then it become useless; We need more detail to check whether being near our home makes us worse at the wheel.
Whenever you are fed data and statistics like this, try to interpret it with fresh eyes. Many people just swallow what the media says, and do not question conclusions that, many times, are not made by specialists but by journalists that need to continuously produce news of some sort.
A common statistic came into my mind today. "Most car accidents happens near the driver's home". Sorry that I do not have a link to this statistic, but in my country that has been said more than once.
It has led people to believe that we are usually more careless or distracted when driving near our homes. Maybe because we are in a hurry, anxious to get to our beloved house and people, or because we are just leaving, not yet fully connected to the action of driving.
I beg to differ; I think this is a misinterpretation of the data. Let's think about it: when you go to work, what streets do you necessarily take? At least the one in front of your home (if you have more than one exit, well, you are blessed, aren't ya? But follow the thought). When going to the supermarket, the mall, a concert, your parent's house, etc., what streets are common in those trajectories? The ones around your home, of course! At the end and beginning of almost every day you are driving around your home.
So, let's assume for a second something more, well, conservative. That the probability of having a car accident on any given street is the same, at least on average. Now, since you are driving near your home much more than you are driving anywhere else, indeed, the probability of an accident in this vicinity is higher!
I'm not saying that distraction may not be a factor here. Those two conclusions are almost equivalent. I'd say that mine seems a little more fundamented of factual, consistent affirmations (since I'd not had to infer that people were distracted), but in any case, if there are at least two reasonable explanations to this data, then it become useless; We need more detail to check whether being near our home makes us worse at the wheel.
Whenever you are fed data and statistics like this, try to interpret it with fresh eyes. Many people just swallow what the media says, and do not question conclusions that, many times, are not made by specialists but by journalists that need to continuously produce news of some sort.
Thursday, September 26, 2013
XmlSerializer vs. DataContractSerializer - An Excellent Resource
Just a quick tip: if you are wondering when to use XmlSerializer and DataContractSerializer, their differences, etc., take a look here.
Since it's on the Wayback Machine, I may reproduce it here once I get the time.
Since it's on the Wayback Machine, I may reproduce it here once I get the time.
Monday, August 5, 2013
Semantic Versioning
Another "found" on the depths of the Internet that I want to leave here for future reference:
http://semver.org
It describes rules for versioning that can be applied to almost anything in software.
http://semver.org
It describes rules for versioning that can be applied to almost anything in software.
Sunday, January 20, 2013
A Jewel: MKLINK
Here I am, late to the party - Microsoft launched mklink back in Vista days, but somehow I managed to miss the
fireworks. There must have been fireworks, man! MKLINK will save your so many
times now that you know it exists, that you will wonder just how you
made it before.
The real thing about MKLINK is not MKLINK itself - it's just a
command-line utility to create file system links. But: file system links!
That is the deal. You see folks, I have some
*nix background. During college I worked on that OS a number of times, and
later on I was part of some projects that had back-ends hosted in a fine Red
Hat rig. In any case, I always missed two things about *nix. The first one was the
command line shell (bash) along with all the command line utilities and the
second one is file system links.
"Just what are file system links?” you may be asking. Links resemble
Windows shortcuts. In fact, it works very similarly to them, but there is a
large difference inside: Intel. Oh, wait, that’s not it. With file system
links, you can create entries in
the file system that point to other entries that are already there.
There you go, the most obtuse definition I have ever written. Let us try
again. When you create a link, you point that link to something. The operating
system then creates a "fake" file on the system that actually is just
another path to access that file. To any application and, in fact, even in the
Windows Explorer, they pretty much like the file they are pointing to. And
yeah, you can do that with folders as well.
Just one more thing to consider when talking about links: they can be either
hard links or symbolic
links.
With symbolic links, you essentially get the same thing as shortcuts.
The link points to the actual record which points to the file. This means that
if you change something like access permissions for the first file, it will
affect the link. Symbolic links can also get "broken", in case you
delete the original file that points to the disk.
Symbolic Links
With hard links, there are no differences between the original entry and the link entry (see picture). The operating system effectively duplicates the record that points to the file on the disk, which results in you having two files that are actually the same (the file is removed only after you delete both entries). Hard links are more powerful but have lot of restrictions; you cannot hard link to a directory, and you cannot have hard link between drives.
![]() |
| Hard Links |
Ufs! I hope I made some sense. In any case, if you still don't get it, check the Wikipedia entry. For now, let's focus on MKLINK.
SCENARIOS
There are many cases where you might want to use links. I will use a
complex scenario, but one that bugged me for a while.
I once worked on a project in which my team was building a .NET application.
The application was build in many layers, and the team decided it was best to
have distinct solutions for stuff like back-end or front-end code. So we had at
least three solutions that produced different DLLs that where necessary to
actually run the application. That may have made managing multiple work streams
easier, but it was hell to get stuff to compile -- we had to get a number of
DLLs out of the Debug or Release folders and then copy then over to the same
location, and then start the application.
Of course, we automated the copy process as part of the build process,
but that was not perfect: for instance, if I made a "clean" in the
solution, the DLLs wouldn't be erased from the "common folder" where
we copied everything.
This let to infrequent but worrisome problems, for instance, the COPY
command could fail and then the application would be ran with out-of-date DLLs.
It also meant a copy step after build, one that got steadily slower as the
application grew.
We could have used links to solve at least part of those problems. All I
had to do was to make a small script that, whenever activated, would clean the
"common folder" and then create there a symbolic link pointing to the
DLL in the Debug folder of each solution. This step did not had to occur at
each compilation, as the symbolic links would always point to the new file. If
I cleaned the solution, all DLLs in the Debug or Release folder would be erased
and the links would be broken, so I wouldn't be able to run the application
with outdated DLLs.
Another interesting scenario is sharing a file between two applications:
maybe it is a large, read-only file, like a picture or even a library or
executable. Instead of having the duplicate residing in your machine, using
twice the space, you can use MKLINK to create a hard link, which will result in
two files that use the data on the disk, saving the space.
One final example: Let us say that you want to synchronize your folders using
a tool such as Dropbox, but pains you to have all your neatly organized files
stashed in the same, outlandish folder, like C:\Dropbox. With symbolic links,
you can organize a directory tree in the Dropbox root folder and then create a
bunch of “symlinks” to those folders in your computer, like this:
"C:\Users\bruno.brant\Project
Data" à "C:\Dropbox\ProjectData"
"C:\Users\bruno.brant\Desktop\Downloaded
Applications" à "C:\Dropbox\Downloads"
Notice that the name of the links is not necessarily the same name as the folder it points to.
This goes a long way into getting stuff organized. Double clicking any
of those folders will take you to the Dropbox folder and it will be completely
transparent to your applications.
SYNTAX AND USE
The tool syntax can be recovered simply by typing mklink /? in your oldie CMD, like this:
C:\> mklink /?
Creates a symbolic link.
MKLINK [[/D] | [/H] | [/J]]
Link Target
/D
Creates a directory symbolic link.
Default is a file
symbolic link.
/H
Creates a hard link instead of a symbolic link.
/J
Creates a Directory Junction.
Link
specifies the new symbolic link name.
Target
specifies the path (relative or absolute) that the new link
refers to.
Let's say you want to create a new link that implements the mapping I
talked about in the final example above, pointing from my downloaded
applications folder to Dropbox. All I'd do is:
C:\> mklink /D
"Users\bruno.brant\Project Data" "C:\Dropbox\ProjectData"
This simple command will result in a new folder in your Users directory which, when opened, always shows you the exact content in the dropbox folder.
RESTRICTIONS
There are a few restrictions to links, as there should, considering they
are not really files.
You cannot use hard links to points to directories. As I said before, hard links
are "duplicates" of files, and the main idea is that you get two different
entries which points to the same location in the disk. However, directories do
not point to places in the disk, they only point to files. If I duplicate a
directory, what happens if one creates a file one of the directories? The
duplicate would have to be updated, but then this means a relationship between
the two... which is exactly what symbolic links are!
You cannot use hard links to point to a file in another partition or
unit. The reason is that if the file entry belongs to one partition, its data
have to be in that partition. It would be illogic to expect that a file in unit
C is actually stored in unit D or a removable drive. However, you can use symbolic
links for that, since Windows already expect that symbolic files do not represent
actual files but point to them, in a fashion.
Thursday, January 10, 2013
Thinking About Your Products As Solutions
The post by Dan Shipper about a talk he had with 37signals' visionary Jason Fried was one of the best reads I've had in blogs recently. One could (but shouldn't) summarize it as "stop thinking about products and start thinking about solutions".
Dan Shipper talks about how customers are always switching to your product from something else. In some cases, it's another product. But when there isn't a competitor product involved, they are switching from a process or even something entirely different.
The first thing that you need to find out is what job your product does.This is something I learned a long time ago and has been in my mind more frequently theses days. I first heard of this concept in a class back in 2002. A professor asked us about McDonald's business. "Sell food" or "sell hamburgers" were most of the answers. "You're wrong", he told us. He said, "McDonald's sell us a full solution package". McDonald's specialty is a solution for parents. You take you kids there and buy a Happy Meal, which includes enough, tasty food to get them satisfied. They also get a toy that will entertain them for a few hours and, on some stores, get to play in giant toys outside.
Dan Shipper talks about how customers are always switching to your product from something else. In some cases, it's another product. But when there isn't a competitor product involved, they are switching from a process or even something entirely different.
That means one of two things: either you don’t understand your product, or no one wants what you’re selling. Every product has competitors. Sometimes they’re other products and sometimes they’re human processes.I for one will try to keep all those ideas in mind when designing my next project. What are people switching from? What is the real goal of my product? What value does it actually brings to the user? Those are all important question that all of us need to answer very early in the designing process.
Tuesday, September 4, 2012
5 Tips for Presenting to Executives
I think this presentation is good value even if you are not presenting to executives, as it covers how to build a presentation that delivers the message fast. Just to give you all a glance:
Nice insights, huh? It's really worth reading.
Nice insights, huh? It's really worth reading.
Tuesday, July 17, 2012
Changing the AudioScrobbler Password Through Registry
So my Winamp's AudioScrobbler plugin (legacy) stops working. The reason: I changed my password in Last.fm but didn't update the plugin settings. Which would be simple, if the plugin didn't crashed Winamp whenever I try to open the configuration screen.
So, after my memory worked and told me that the reason was actually the password, and after I searched the net for a new plugin version that wouldn't crash and found nothing, I decided to change the password by myself.
First I looked at the Winamp's plugin folder (Winamp\Plugins) for a configuration file. I was pretty sure the file had to be there, after all, you deploy plugins in Winamp by simply coping the DLL to that folder. And I know some AudioScrobbler files are there - I fumbled with it's cache once back in 2007. However, besides the cache and a log, I couldn't find any files.
Next stop: Windows registry. A quick find for "AudioScrobbler" did the trick, and there it was, a key named "password"... which, my wits told me, ought to contain my password! Fortunately, I remembered the old password: key was hashed and I needed to find which algorithm was used. So I tested a few, producing hashes from my old password: SHA-1, SHA-2, MD5... bang! The key was hashed with MD5. Easy enough.
All I did then was produce a MD5 hash of the new password and replace it in the key. After firing up Winamp, I checked the log to make sure the connection was working again and that's it.
P.S.: I shared this story just to show how we can use our programming knowledge to solve problems without programming and because it was a long time since I last did some dirt trick like this, so I felt a little proud of myself.
P.P.S.: Also, the website linked to above has the source code for a previous version of the plugin. Maybe, if I find the time, I'll update it so it doesn't crashes in Windows 7 x64 and post it in GitHub. I don't know how many people still uses this plugin (or even Winamp for that matter) but I love it and want to share it.
Subscribe to:
Posts
(
Atom
)






