How do you learn a new platform/toolkit while producing working code and keeping your codebase clean?
When I know what I can do with the underlying platform and toolkit, I usually do this:
- I create a new branch (with GIT, in my case)
- I write a few unit tests (with JUnit, for example)
- I write my code until it passes my tests
So far, so good. The problem is that very often I do not know what I can do with the toolkit because it is brand new to me. I work as a consulant so I cannot have my preferred language/platform/toolkit. I have to cope with whatever the customer uses for the task at hand.
Most often, I have to deal (often in a hurry) with a large toolkit that I know very little so I’m forced to “learn by doing” (actually, programming by “trial and error”) and this makes me anxious.
Please note that, at some point in the learning process, usually I already have:
- read one or more five-stars books
- followed one or more web tutorials (writing working code a line at a
time) - created a couple of small experimental projects with my IDE
(IntelliJ IDEA, at the moment. I use Eclipse, Netbeans and others,
as well.)
Despite all my efforts, at this point usually I can just have a coarse understanding of the platform/toolkit I have to use. I cannot yet grasp each and every detail. This means that each and every new feature that involves some data preparation and some non-trivial algorithm is a pain to implement and requires a lot of trial-and-error.
Unfortunately, working by trial-and-error is neither safe nor easy. Actually, this is the phase that makes me most anxious: experimenting with a new toolkit while producing working code and keeping my codebase clean.
Usually, at this stage I cannot use the Eclipse Scrapbook because the code I have to write is already too large and complex for this small tool. In the same way, I cannot use any more an indipendent small project for my experiments because I need to try the new code in place. I can just write my code in place and rely on GIT for a safe bail-out. This makes me anxious because this kind of intertwined, half-ripe code can rapidly become incredibly hard to manage.
How do you face this phase of the development process?
How do you learn-by-doing without making a mess of your codebase?
Any tips&tricks, best practice or something like that?
3
I find the best solution is to not learn by doing in that way.
Rather than immediately trying to solve your problem, isolate what you don’t understand and figure that out first.
Take a trivial example, you don’t know how Nullable
works in the .NET framework. Rather than attempting to write code using it, create a sample application and play around with it.
For example:
public static void Main(string[] args)
{
var test = new int?();
Console.WriteLine("new int? - {0}", test);
test = 0;
Console.WriteLine("0 - {0}", test);
test = 1;
Console.WriteLine("1 - {0}", test);
test = null;
Console.WriteLine("null - {0}", test);
Console.WriteLine("test == null - {0}", test == null);
Console.WriteLine("test.HasValue - {0}", test.HasValue);
Console.WriteLine("test.GetValueOrDefault() - {0}", test.GetValueOrDefault());
Console.WriteLine("test.GetValueOrDefault(2) - {0}", test.GetValueOrDefault(2));
}
Throwing in any examples you find and seeing what happens. This allows you to perform the unit testing style of exploration you are used to without having to run a complex code base through your tools.
Note that this can sometimes work with existing code bases. Be careful of assumptions about the running environment however. If you call a DLL that expects to be running in an IIS environment from an EXE you may run into some odd errors.
1
Assuming you have read some books and documentation, the only way to go forward from there is to practice. You are lucky in that when you are a consultant that you already have a
project that needs doing, so you can just start doing it.
In general, I think your current approach is correct.
You
a) Learn the background and the theory.
b) Create tests fot TDD.
c) Start working.
The only thing I would add is
d) Refactor when you learn/discover a better way of doing something that you’ve already done.
The above is IMHO always the right approach to new frameworks. You can’t expect to read books and docs until you know EVERYTHING and only then start coding. The human mind doesn’t work like that, and even if it did that would probably be sub-optimal.
Well I’m by no means a pro, but I learn as the process goes on, learning and implementing new features as they’re needed, however I have the luxuries of time and being a student.
As far as I can tell, you’re doing a pretty good job of keeping up with all the changes.
The only tip I can give as a beginner is to break it down into consumable bits, and learn the features you need side by side with the basics of the toolkit/platform so that you can code the trivial code faster and be satisfied with your overall code.
I was going to suggest that you make a throwaway project to familiarize yourself with the tool
but you’ve already got that covered. There will always be more the to tool than books, tutorials, and sample projects can show
you. All the nuances come out only with experience. But if you don’t feel you have a sufficient grasp on a tool, I’d simply
spend more time on those three steps.
You plan seems solid to me.
I work as a consulant
Oh. Well, in that case, FAKE IT. Deliver whatever you can slap together in a roughshod manner that appears to work, bill
the customer for meeting your contractual obligation, and leave. If it’s not the prettiest, that’s someone else’s problem. Or it’s seeding for future employment. Thus is the life of a contractor. If you have specific domain knowledge about whatever, be sure
to fork that over in a handy document or tool or example code, as that’s what they’re really paying you for. But if they just need a code-monkey for a weekend, and
they don’t let you use the tools you know, then this is the sort of results they should expect. Sorry, but that’s how piece-meal work
turns out. If you put in that extra effort, another consultant will undercut you. If your client was hiring for quality,
they’d have actually HIRED someone.
Don’t get me wrong, consultants can be a god-send when you need a superman of SQL or a gnu guru to banish the bugs that plague you.
But hiring a consultant who has to learn the tools? naw.
7