Thursday, September 4, 2014
Generic result class with C#
Summary
Introduction
IStudentRepository
Generic result
Caveat L
Tuesday, February 2, 2010
Silence is not golden
Monday, November 16, 2009
Google Waves is finally here
In the screenshot, that was me, Lawrence Mateveke, and Victor Mudziviri communicating via waves.
Monday, August 31, 2009
Some Crazy Code Not out there, but here within
I heard from somebody (won't mention his name), that somebody who is a follower on this blog (won't mention the name either) has been busy writing some piece of code, what I consider to be a a great work of code-art. The word is - this dude has written a crawler! You know that thingy don't you guys? That thing that goes around computer networks, crawling on every network computer and gathering information on that computer.
The unnamed source also disclosed that this fellow now has a database with over 9000 records of information on a certain country in a certain continent, all gathered with the 'crawler'.
What I want to know, is what language that crawler was written in? I presuppose it's written in JAVA or Python. And then I want to know the algorithm(s) behind this. That fellow is a genius if you ask me.
It appears after all, that while we were sleeping some great mind has been writing some excellent piece of code.
Or is it this fellow only? What is everybody else working on?
What crazy price of code have you written lately? I read on TKMUNZWA's blog sometime ago about how he wrote some crazy shell script on linux that monitors whether or not a headless computer is connected to the internet 24/7,. I wish to quote it here (the assumption is, if it's on a public blog, i won't be sued for plagiarism). He did it in 2 scripts. The first one below is called checkinternet.sh and the second one is called soundalarm.sh For more information visit http://munzwa.tk/blog/
#!/bin/sh
if eval "ping -c 1 google.com";then
# echo "connected to internet"
killall soundalarm.sh
else
# echo "not connected to internet"
/var/local/soundalarm
#!/bin/sh
while [ 1 ]
do
for F in 1000 1500 2000 2500 3000
do
beep -f $F -l $(($F/50))
done
#sleep 1
done
Some crazy yet very useful piece of code don't you think?
Anyways, before I name the culprit behind the 'crawler' I am giving you a chance to come forward and tell us all about this 'crawler'. Perhaps we might be inspired to come up with crazy code too.
Long live Code, and long live JAVA.
Friday, May 29, 2009
MyGeneration : A Tool you should try
Monday, April 20, 2009
Oracle to buy Sun Microsystems
Tuesday, February 24, 2009
Don't Eat A Person Who Is Working... LOL!!
During the welcoming ceremony the boss says: "You're all part of our team
now. You can earn good money here, and you can go to the company canteen
for something to eat. So don't trouble the other employees". The cannibals
promise not to trouble the other employees.
Four weeks later the boss returns and says: "You're all working very
hard, and I'm very satisfied with all of you. One of our developers has
disappeared however. Do any of you know what happened to her?" The
cannibals disown all knowledge of the missing developer. After the boss
has left, the leader of the cannibals says to the others: "Which of you
idiots ate the developer?"
One of the cannibals raises his hand hesitantly, to which the leader of
the cannibals says: "You FOOL! For four weeks we've been eating team
leaders, managers, and project managers and no-one has noticed anything,
and now YOU ate one developer and it got noticed. So hereafter please
don't eat a person who is working."
Programming Sucks! Or At Least, It Ought To
Shamelessly ripped from TheDailyWTF article written by Alex Papadimoulis
Programming is not fun. It’s boring, it’s tedious, and it’s certainly not challenging. And no matter how much you stretch it, programming is most definitely not sexy.
I know what you’re thinking. Anyone who says that – let alone blogs it – should immediately be stripped of his software development license, have his keyboard taken away, and be permitted to only use only to CP/M on 8" floppies with a 1200 baud modem.
Obviously, a lot of us – me included – enjoy writing code. But should we?
Why do we write code?
Software development is a unique profession in that we can use our skills both on the job and for our hobby. And unlike accountants, who generally don’t rush home to balance the family budget, many of us actually do tinker with code for fun.
But for the sake of this article, let’s only consider the non-hobbyist developer, and the work that he does. In fact, let’s narrow this down even further, and consider only developers of “boring” software. And by “boring”, I mean bills of lading processing, corporate fleet usage tracking, expense report creating, etc., all for internal use with lots and lots of company-specific requirements. So, to reiterate, if you don’t create “boring” software for a living, then this article doesn’t fully apply.
While the line between “boring” and “sexy” software can be blurred at times, sexy software represents the type of things that we use on a regular, day-to-day basis: SVN, Google Maps, Visual Studio, Firefox, etc. In fact, as software developers, we rarely have to use boring software ourselves.
From a development perspective, however, the percentages are flipped. Only a select few get paid to develop “sexy” software, whereas most of us are stuck developing the boring stuff.
Basics of Boring Software
There’s a term for this type of boring software: information systems. And while the purpose of an information system changes from company to company, as do the specific requirements, they all are essentially the same. There’s a database that models the real world, rules to define how the data may be changed, an interface to the database, and lots of different reports.
The formal process of creating these information systems was first created in the sixties and hasn’t changed much since the seventies (Modern Structured Analysis is surprisingly still modern). Essentially, you analyze the problem, map the dataflow, structure the dataflow, create the database, and create programs that interface with the database.
We’ve gone from thin-client green screen terminals to thick-client PC applications. Then we went to the thin-client web and, with platforms like Windows Presentation Foundation, we’ll be back to thick-client in no time. But either way, the systems do all the same thing: data in, data out.
Developing information systems hasn’t changed much, either. Whether you’re using Visual Basic 3.0 or XHTML, the concepts are pretty much the same: the database needs to be exposed to the user in user-friendly terms. The code required to do this is, and always has been, fairly tedious:
txtFirstName.DisplayWidth = 30;
txtFirstName.MaxCharLength = 50;
SetTextBoxValidator(txtFirstName, Validations.LettersOnly);
txtFirstName.Enabled = securityContext.CanEdit;
txtFirstName.Value = customerRecord.FirstName;
That’s five lines of code just to set some UI properties. Multiply that for every field, for every entity, and then by 1.5, just because some fields have to be accessible in two different places. Now add in all the code required to validate and save data from the UI. If my math serves me right, that adds up to a crapton of tedious, boring code.
The Developer’s Dilemma.
“Tedious” and “boring” are two words that don’t sit well with developers. We’re an analytical bunch and oftentimes come with a computer science degree. And we’re much more capable than tying a front-end and a back-end together using line after line of code. Perhaps we could even use our skills and capabilities to make our job easier.
And therein lies the rub. As Michael A. Jackson said in his 1975 Principles of Program Design, “Programmers… often take refuge in an understandable, but disastrous, inclination towards complexity and ingenuity in their work. Forbidden to design anything larger than a program, they respond by making that program intricate enough to challenge their professional skill.”
This thirty-five year-old observation is confirmed day-in and day-out here on TDWTF. Some of the most egregious code and stories written here stem from the developer’s desire for cleverness. Carrying out these desires is neither malicious nor devious, but merely instinctual.
When I wrote about Soft Coding, I presented a snippet of business code to illustrate what the majority of code should look like: i.e., very specific code to implement very specific business requirements. It’s pretty boring:
private void attachSupplementalDocuments()
{
if (stateCode == "AZ" || stateCode == "TX") {
//SR008-04X/I are always required in these states
attachDocument("SR008-04X");
attachDocument("SR008-04XI");
}
if (ledgerAmnt >= 500000) {
//Ledger of 500K or more requires AUTHLDG-1A
attachDocument("AUTHLDG-1A");
}
if (coInsuredCount >= 5 && orgStatusCode != "CORP") {
//Non-CORP orgs with 5 or more co-ins require AUTHCNS-1A
attachDocument("AUTHCNS-1A");
}
}
In the numerous responses to the article, some people offered some rather humorous feedback, demonstrating ways that the code could be “complexified”. These examples were, sadly, fairly representative of what I’ve actually come across in response to simple business requirements.
Others offered some serious refactoring suggestions involving all sorts of design patterns, interfaces, supplementers, and a whole lot of classes. Naturally, all without ever seeing the module that the hypothetical code resided in, let alone a broad understanding of the overall system and its requirements.
And then there was this one guy, James Taylor, who basically called me an idiot for suggesting that developers get their hands dirty with business rules. Apparently, we should all be building whiz-bang expert systems with fancy UIs that let the end user do all of the dirty work.
Of course, those of us ground in reality understand that such expert systems exist only in the land of pixie dust, unicorns, and lossless compression of random data. But there’s another reality that many of us have yet to accept: application development sucks, and no amount of XML or design patterns will change this.
Just Suck It Up.
It’s not easy to reconcile the fact that the software we write each and every day is, for all intents and purposes, mind-numbingly boring. Magazine subscription management. Medical billing reports. Realty inventory management. This is not the type of software that changes the world. In fact, it probably won’t even put a smile on someone’s face. Its sole purpose is to add to the bottom line by making other workers be more productive.
As unexciting as it may be, it’s our job to do work *exclusively* to benefit our employer, not for own personal satisfaction. That’s just what it means to be a professional.
I’m sure that many aspiring lawyers would jump at the chance for an exciting jury trial, but would just as quickly give it up if it was in his client’s best interest to settle. While architects dream of opportunities like Fallingwater, if the design calls for a large warehouse with loading docks, then that’s all the blueprints will reflect. And if our employer needs software to manage voucher payments, then they should get exactly that, not a “plug-in based system with extensible, run-time parsed UI templates,” or whatever else we tricked ourselves in believing was necessary.
Rethinking Software Development.
As frustrating as it can be to work with the uninspired, sloppy developer, the contrary – the inspired-yet-misguided one – is several magnitudes worse. A few bugs and painful-to-maintain code pale in comparison to the disastrous results an improperly motivated developer can deliver.
Everything from the platform (“let’s try out Ruby!”) to the architecture (“can’t just have two tiers”) to the techniques used in the code itself (“we need an aspect-oriented framework”) can be – and often are – influenced more by the desire to learn the technology than to serve the actual business need. Pick the wrong platform or invent the wrong technique, and the project is inevitably doomed.
Having doomed more than one project as a result of my desire to challenge myself, I’ve come to learn that there are some essential rules that must be followed when developing business information systems.
1. Learn the Business. It’s preposterous to believe that you don’t need to understand the business in order to develop software for the business. Without understanding what their actual needs are, it’s impossible to give stakeholders what they actually need. That’s right: when they say they want a “new database for every day”, they don’t actually mean a new database for every day.
2. Serve the Business. Every tradesman wants to use the latest, greatest, and most powerful tools, but rarely are they appropriate for the job. Likewise, there’s hardly ever a business case to immediately upgrade all platforms/libraries/languages. That 10-year old “Classic ASP” code hasn’t gotten worn out, just much less fun to maintain.
3. Learn Off The Job. Self-improvement is a tenet of every profession, but the place to do that is “off the job,” i.e. not while developing information systems1. Instead, learn by creating applications for yourself, your team, or perhaps even some open source project.
4. Code mostly Business. If the overwhelming majority of your hand-written code isn’t domain-specific and doesn’t relate to the application’s purpose, then you’re using the wrong tools. If you truly believe that the system needs a custom logging framework, then externalize it and get a buy-in from the stakeholder.
5. Tedium is Inescapable. No O/R-mapper or code-generator can ever solve the fact that records, fields, validators, etc. need to be defined, by hand, in at least two places (front- and back-end). A UI generated from the database is just as bad as the database that’s generated from the UI.
6. Find Satisfaction Elsewhere. If your only satisfaction comes from writing complex code, then you’ll never be a good and satisfied applications developer. Personally, I’m happy to know that I helped increased productivity for the end-user and/or created new opportunity for the organization.
... and, if all else fails...
7. Get Another Job. Maybe you’ve reached your value apex. Or maybe you’re just sick this type of development altogether. Either way, there are plenty of programming opportunities out there that don’t involve boring, information systems. Of course, the competition is much fiercer since the Paula Bean-types seem to only fly under Corporate IT's radar.
At the end of the day, the best programmers are not the ones who create the most beautifully-elegant, exceedingly-innovative code. The true rockstars can deliver software before deadlines, under budget, and that does exactly what the business needs. And those are the type we should all strive to be.
UPDATE: 1 To clarify, “off the job” does not mean that you should’t learn at work. Learning is important, but don’t do so while developing an information system for the stakeholder (“on the job”). Save that for your own or your team’s internal projects.
Monday, February 23, 2009
Be careful
Here's Another Article I picked up...
I have been going through a lot of self reflection as of late, and as you can imagine there are a number of things that haunt my current psyche.
One of these such things is coming to the realization of just how special I thought I was as a college graduate. After all, I had shed the skin of the cocky teenager and had a true grasp of who I was and what I was capable of. I had degrees. I worked at Microsoft. Martin Fowler look out - there’s a new guy in town…
Although I can say (with little ego) that I did have a lot going for me, and I had accomplished a lot - I knew little to nothing about the real world.
You see, college never allowed me to learn through failure. As Alan Watts below puts it, I was placed in this “nursery society” where I was allowed to believe that real life was about pretending, having fun, and no matter what things will be alright.
Translating that into software development, I never had to write programs that lasted more than the next weekly project. As a result, my solutions were short sited, problematic, and all-round crap. But I didn’t need to care, as long as the teacher did not find that one little bug I swept under the rug or care about code maintainability or the fact that there were no tests - after all, it’s always a sunny day in Disneyland.
In a sense, college wired my habits to approach solutions wrong. I went to college to grow into an adult, and came out an over confident child.
Recent graduates and veteran developers alike take heed - we all have a lot to learn about our profession and even more about ourselves. Never allow your confidence to block your ability to learn from the mistakes of yourself and others. After all, we all graduated from the University of Mickey.
For the true significance of Disneyland is that it reflects our notions of children - what they are, what is good for them, and what will please them. Children are a special class of human beings which came into existence with the industrial revolution, at which time we began to invent a closed world for them, a nursery society, wherein their participation in adult life could be delayed increasingly - to keep them off the labor market. Children are, in fact, small adults who want to take part in the adult world as quickly as possible, and to learn by doing. But in the closed nursery society they are supposed to learn by pretending, for which insult to their feelings and intelligence they are propitiated with toys and hypnotized with baby talk. They are thus beguiled into the fantasy of that happy, carefree childhood with its long sunny days through which one may go on “playing” - in the peculiar sense of not working - for always and always. - Alan Watts, Does It Matter?: Essays on Man’s Relation to Materiality
Tuesday, January 13, 2009
When a developer looks for another job.. LOL!!
Something I picked on www.codesqueeze.com .
Very very helpful
In this fast paced and economically burdened society, it is only natural for the majority of us to ask ourselves how can we fortify our careers. Do we solidify our current positions? Or should we diversify our experience and resume?
A number of people have asked me this question lately all with the same concerns - they feel their current skill set does not provide them with all the job opportunities they need in order to feel comfortable.
The truth is it is completely possible to land a job without knowing anything at all about the technology or domain for which you are applying for. The only thing you need to prove is your ability to quickly learn and adapt (however, I hope that it is obvious that the less you know the more convincing you will have to be).
Many people are fearful of even applying for positions where they do not meet (or exceed) the requirements of the job description. Pffft I say.
Remember in Star Wars how C-3PO talked himself into the graces of Uncle Owen?
Uncle Owen: You, I suppose you’re programmed for etiquette and protocol.
C-3PO: Protocol? Why, it’s my primary function, sir. I am well-versed in all the customs–
Uncle Owen: I have no need for a protocol droid.
C-3PO: Of course you haven’t, sir. Not in an environment such as this. That is why I have been programmed in–
Uncle Owen: What I really need is a droid who understands the binary language of moisture vaporators.
C-3PO: Vaporators? Sir, my first job was programing binary load lifters very similar to your vaporators in most respects.”
Uncle Owen: Can you speak Bocce?
C-3PO: Of course I can, sir. It’s like a second language to me. I’m a–
Uncle Owen: yeah, alright. Shut up. I’ll take this one.
C-3PO: Shutting up, sir.
There are three simple rules to remember. Master these and you will never be scared of unemployment again.
1. You will never fit the job description 100%
Don’t even get me started on this topic because for some stupid reason employers ask for job skills that even most astronauts don’t possess. Getting hung up in the fact that you don’t fully qualify all the skills is the first stumbling block.
Even if you aren’t their picture perfect candidate, you might be the best for the job out of everyone that applied.
2. Find and flaunt parallel skills
C-3PO didn’t know binary vaporators, but he did know binary load lifters. Don’t know Java? The last 4 years of C# just might be enough to prove you understand it enough.
You would be amazed at how many parallel skills you can draw with what skills are being asked. Really ask yourself, are they asking for an Exchange Server expert or are they asking if I am a capable email administrator that can handle an Exchange server?
3. Shut up
When they decide they like you - shut up. Don’t give up any more information than you need to as it will only hurt you. Just like C-3PO, you might find yourself getting jettisoned if you ramble on.
It is always better to gain new experience and skills; however, do not worry about lacking the knowledge of everything the universe has to offer. Proving that you know how to learn, unlearn, and relearn is the greatest thing you can offer an employer.
Monday, January 5, 2009
Now is the time for action..
I have been thinking (for a long time now) why we havent put a name for ourselves when we are such good developers. I know we are all busy with work items but i believe this is the year big things should happen in our programming lives, unless i am an optimists. (Optimist: glass is half full ; Persimist: glass is half empty).
To start with i would want to pose a question to everyone on this forum. What did we do last year that was not part of your work? I know some got married, congrats, but when it comes to programming, did we archieve anything or we are letting those Java/PhP/Postgres skills rot in the back of our mind. It pains me to realise all those bright ideas and dreams i once envied at College have suddenly gone to the bin!
To cut my story short i will challenge you guys to come up with something for this year and the future. I am not thinking of something commercial but, if possible lets take it up. I am sure almost everyone has something at his work place that they wish could be automated to save a lot of effort and time. I know within this forum we have people who know java/php/asp/c#/vb/j#/jsp/python and almost all databases. So i am saying guys lets come up with a sort of a "Open Source" Project(s). This is our time and lets make use of it.
Let me hear what others think.
Thursday, December 11, 2008
Powerful .NET Technologies
I have written this post to address several technologies available to dot net developers that I consider exciting to work with. I will dwell into the details of each of the technologies in future posts. I do recommend that non dot net developers try to understand the rationale behind the technology and possibly find you dev environment equivalent or better still pioneer your own projects to add these into your platform. In this post I will give an introduction to four technologies in dot net namely, Language Integrated Query(LINQ), Windows Communication Foundation(WFC), Windows Presentation Foundation(WPF) and Windows Workflow Foundation WWF. I will go right ahead and give you a feel of what each is all about
LINQ
LINQ is Microsoft’s technology to provide a language-level support mechanism for querying data of all types. These types include in-memory arrays and collections, databases, XML documents, and more. Virtually any data store would make a good candidate for supporting LINQ queries. This includes databases, Microsoft’s Active Directory, the registry, the file system, an Excel file, and so on. LINQ offers a compact, expressive, and intelligible syntax for manipulating data. The real value of LINQ comes from its ability to apply the same query to an SQL database, a Dataset, an array of objects in memory or an XML file. LINQ requires the presence of specific language extensions.
LINQ uses an SQL-like syntax to make query expressions well beyond the capabilities of embedded SQL as implemented in programming languages. That's because embedded SQL uses a simplified, streamlined syntax to add SQL statements to other programming languages, where there's no attempt to integrate such statements into the native syntax and typing mechanisms. Thus, you can't invoke native language structures such as functions in embedded SQL statements, as you can using LINQ, because it is implemented to use native syntax, structures, and typing mechanisms. Furthermore, LINQ may be used to access all kinds of data, whereas embedded SQL is limited to addressing only databases that can handle SQL queries. Here is an example of using linq to SQL
WCF simplifies development of connected applications through a new service-oriented programming model. WCF supports many styles of distributed application development by providing a layered architecture. At its base, the WCF channel architecture provides asynchronous, untyped message-passing primitives. Built on top of this base are protocol facilities for secure, reliable, transacted data exchange and broad choice of transport and encoding options.
The typed programming model (called the service model) is designed to ease the development of distributed applications The service model features a straightforward mapping of Web services concepts to those of the .NET Framework common language runtime (CLR), including flexible and extensible mapping of messages to service implementations in languages such as Visual C# or Visual Basic. It includes serialization facilities that enable loose coupling and versioning
With WCF, distributed applications are much easier to implement, due to the following facts
Because WCF can communicate using Web services, interoperability with other platforms that also support SOAP, such as the leading J2EE-based application servers, is straightforward.
- You can also configure and extend WCF to communicate with Web services using messages not based on SOAP, for example, simple XML formats like RSS.
- Performance is of paramount concern for most businesses. WCF is developed with the goal of being one of the fastest distributed application platform developed by Microsoft
- To allow optimal performance when both parties in a communication are built on WCF, the wire encoding used in this case is an optimized binary version of an XML Information Set. Messages still conform to the data structure of a SOAP message, but their encoding uses a binary representation of that data structure rather than the standard angle-brackets-and-text format of the XML 1.0 text encoding. Using this option makes sense for communicating with the call center client application, because it is also built on WCF, and performance is an important concern.
- Managing object lifetimes, defining distributed transactions, and other aspects of Enterprise Services are now provided by WCF. They are available to any WCF-based application, which means that your application can use them with any of the other applications it communicates with.
- Because it supports a large set of the WS-* specifications, WCF helps provide reliability, security, and transactions when communicating with any platform that also supports these specifications.
- The WCF option for queued messaging, built on Message Queuing, allows applications to use persistent queuing without using another set of application programming interfaces.
The result of this unification is greater functionality and significantly reduced complexity.
WWF
Most businesses require processes to function properly. There are different types of processes. Some processes are human-intensive, others machine-intensive, and the last type is a combination of the first two. Some examples of business processes are payroll, new product introductions, new employee hiring, etc. In most cases, these business processes require intervention from multiple entities and thus, are normally long running. Workflow is one of the mechanisms used by businesses to express their business processes as a series of self-contained activities. Business Process Management (BPM) systems provided an environment for developers to create, execute, and manage workflows. These workflows are normally expressed using Finite State Machine (FSM), Unified Modeling Language (UML) Activity Diagrams, UML Swim Lanes, or Flow Charts. WF technology complements the .NET Framework with a group of workflow-related components that allow developers the ability to define, compile, instantiate, debug, and track workflows. This technology will become part of WinFX together with Windows Presentation Foundation, and Windows Communication Foundation.
WF workflows are composed using activities. Activities represent discreet pieces of functionality that are used to run specific business activities. There are two types of activities: composite and individual activities. Composite activities are used to express control statements (i.e., While, For, If-Then-Else, Case, etc.) and for grouping activities that share behavior (i.e., Sequences, Conditioned Activity Groups, etc.). Also, these activities are used to develop reusable sub-processes or sub-workflows. On the opposite side, individual activities provide a mechanism for expressing single pieces of work that need to be executed in the same step in the workflow.The workflow run time is responsible for taking workflow definitions and instantiating them. The life cycle of the workflow instances are managed by the workflow runtime. It is responsible for creating, executing, threading, persisting, tracking, communicating execution events, and coordinating transactions. These functions are managed by the workflow run time via services. There is a set of default services that the run time uses to manage all of its workflow instances, threading, transactions, tracking, state management, etc. Application developers responsible for integrating workflows into their existing applications can overwrite these services. Using this service model, developers are able to expose their existing hosting infrastructure to the workflow library. The framework provides a set of out-of-box services that allow developers to quickly start using the environment without worrying about having to write complicated code.
WPF
Windows Presentation Foundation is a development tool for Web applications and rich client applications. With WPF, developers can use XAML, the Extensible Application Markup Language, to create custom controls, graphics, 3D images and animations that are not available in traditional HTML implementations.