Thursday, August 28, 2008
SLOC can be good for your morale (II)
Here is the theory, below is the result: my last refactoring as seen through the eyes of SourceMonitor:
Tuesday, August 12, 2008
Wednesday, July 16, 2008
SLOC can be good for your morale
While Wikipedia tells you there are 2 advantages and so many as 9 disadvantages for using the SLOC metric in software programming, I'll tell you yet another advantage.
Start by thinking about TDD and the psychological reason why TDD is good: it shows you red turning to green, effectively rewarding you for the done job.
Now I've stepped into a project with such a scrambled source code that I find myself constantly refactoring while doing other tasks. Sometimes the refactoring gets bigger and turns into a standalone job and this is the case when I'd love to see a line like this one on my display after I'm done: Great job, you maintained all the functionality, all tests pass, the code base is smaller and easier to understand!
Ok, I'm giving the tools too much credit ... I'll run the tests myself and ensure the functionality is preserved. But hey, what about the code base is smaller and is easier to understand! To a big extent I think the shorter the better, and to skip the debate let's take the proof to the extreme, just go through the C - Cobol code comparison here and see which one is easier to grasp. You're right, the shorter one.
This means you can measure (part of) the success of a (big) refactoring with a metric derived from SLOC, along the lines of effective SLOC, this as long as the tool that computes this metric for you is smart enough to yield the same results for:
Start by thinking about TDD and the psychological reason why TDD is good: it shows you red turning to green, effectively rewarding you for the done job.
Now I've stepped into a project with such a scrambled source code that I find myself constantly refactoring while doing other tasks. Sometimes the refactoring gets bigger and turns into a standalone job and this is the case when I'd love to see a line like this one on my display after I'm done: Great job, you maintained all the functionality, all tests pass, the code base is smaller and easier to understand!
Ok, I'm giving the tools too much credit ... I'll run the tests myself and ensure the functionality is preserved. But hey, what about the code base is smaller and is easier to understand! To a big extent I think the shorter the better, and to skip the debate let's take the proof to the extreme, just go through the C - Cobol code comparison here and see which one is easier to grasp. You're right, the shorter one.
This means you can measure (part of) the success of a (big) refactoring with a metric derived from SLOC, along the lines of effective SLOC, this as long as the tool that computes this metric for you is smart enough to yield the same results for:
andi++;andi = i + 1;
P.S. Guess what, I've edited the post and made it shorter ;)void m() {and
date = new Date();
}void m() {
n();
}
void n() {
date = new Date();
}
Monday, June 23, 2008
hiring
If you say to me How are you? these days and don't expect a useless, no-substance Western answer like Not so bad, I'll reply back with Good, hiring.
And it is the HOW I am doing it that matters this time. I am putting extra effort to eliminate phonies in interviews, those that sound brilliant and don't do the job, so you'll get a hands-on test at the end of the 2h interview which is structured like this:
- discussion on recent projects and professional experience
- questions from various subjects like algorithms, data structures, technologies, software development
- hands-on test
I am only looking for 2 engineers, so hiring one not good for the job will mean 50% failure. Fingers-crossed.
And it is the HOW I am doing it that matters this time. I am putting extra effort to eliminate phonies in interviews, those that sound brilliant and don't do the job, so you'll get a hands-on test at the end of the 2h interview which is structured like this:
- discussion on recent projects and professional experience
- questions from various subjects like algorithms, data structures, technologies, software development
- hands-on test
I am only looking for 2 engineers, so hiring one not good for the job will mean 50% failure. Fingers-crossed.
Wednesday, June 11, 2008
XML and aliens
[...] If SETI@home works, for example, we'll need libraries for communicating with aliens. Unless of course they are sufficiently advanced that they already communicate in XML. [...] - Paul Graham
Man, this line is so good, I had to reproduce it here and post yet again a link to Paul Graham's essays so that other know-it-all programmers can read them and realize they know next-to-nothing.
Humble me.
Man, this line is so good, I had to reproduce it here and post yet again a link to Paul Graham's essays so that other know-it-all programmers can read them and realize they know next-to-nothing.
Humble me.
Monday, March 24, 2008
soap with attachments, axis1 and href
Warning: Read on only if these terms together instantly give you a headache or bring you bad memories.
If you use axis in your project (and indeed it hides nicely the details of constructing SOAP messages and lower level APIs like SAAJ) you probably write code like this to invoke a remote service with attachments:
But it might be that unless your business object (that Axis will serialize into the BODY part of the SOAP message) will reference the attachment, the remote system will simply ignore the attachment, or worse, your entire message.
This linking is not something the Axis guys invented, just something that they made harder to control. See http://www.w3.org/TR/SOAP-attachments for the different ways to link the SOAP message with the attachment within a MIME message.
...and here is how you could do it with Axis while leveraging the classes that
It might be that the same works with axis2, your turn to test and let me know. As for MIME and DIME attachment encodings, both work, just use this extra code for DIME attachments:
Did it work? No?! You must have done smth wrong ...
If you use axis in your project (and indeed it hides nicely the details of constructing SOAP messages and lower level APIs like SAAJ) you probably write code like this to invoke a remote service with attachments:
X_BindingStub service =
(X_BindingStub) new X_ServiceLocator().
getY([<url>]);
service.setUsername(<username>);
service.setPassword(<password>);
MyBusinessObject obj = new MyBusinessObject();
obj.setXXX(...);
service.addAttachment(new DataHandler(...
service.remoteMethod(obj);
But it might be that unless your business object (that Axis will serialize into the BODY part of the SOAP message) will reference the attachment, the remote system will simply ignore the attachment, or worse, your entire message.
This linking is not something the Axis guys invented, just something that they made harder to control. See http://www.w3.org/TR/SOAP-attachments for the different ways to link the SOAP message with the attachment within a MIME message.
...and here is how you could do it with Axis while leveraging the classes that
wsdl2java generated:Service service = new Service();
Call call = (org.apache.axis.client.Call)
service.createCall();
// set call endpoint, username, password
// locate the description of the remote method you want
// to call in X_BindingStub and use it here:
OperationDesc oper =
new org.apache.axis.description.OperationDesc();
oper.setName("remoteMethod");
ParameterDesc param ...
...
call.setOperation(oper);
// locate the remote method you want to call in
// X_BindingStub and use that code fragment here:
call.setUseSOAPAction(true);
...
call.setOperationName(new javax.xml.namespace.QName(...
// create the attachment
AttachmentPart ap = new AttachmentPart(new DataHandler(
"All my worries are gone now", "text/plain"));
String contentIdRef = ap.getContentId();
// construct the XML string that the remote function
// expects (it'd be very easy if you could take this from
// the remote service logs). Link to the attachment by
// setting the href attribute of an XML elem. Note that
// the remote method must expect the href attribute on
// the very XML elem where you place it
String xmlString = "<xxx>...href=\""
+ contentIdRef + "\"...</xxx>";
// call the remote service
call.addAttachmentPart(ap);
call.invoke(new Object[] {new SOAPBodyElement(new
ByteArrayInputStream(xmlString.getBytes("UTF-8")))});
It might be that the same works with axis2, your turn to test and let me know. As for MIME and DIME attachment encodings, both work, just use this extra code for DIME attachments:
call.setProperty(
Call.ATTACHMENT_ENCAPSULATION_FORMAT,
Call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);
Did it work? No?! You must have done smth wrong ...
Tuesday, March 11, 2008
works as designed
You definitely heard this one, developers use it as a reason for closing bugs, you even used it yourself. It sounds perfectly natural, at least to me, the developer. I bet testers hate it. 3 simple words to close a bug with.
And now I'm questioning if the construct is correct. How much sense does design make to a tester? And considering that some teams have this open policy where clients can see all the product bugs, how much sense does design make to a client?
To find out the answer, try this: in UAT, go to your client and tell her that the bug she thinks she found is actually the behavior as designed. Don't be surprised if she asks you What design? Now if you are smart you'd shut up and go check the spec that she counter-signed, if you are not-so-smart (read stupid or inexperienced) you'd say: What design?! The UML class design, the interaction and ORM diagrams!
By now the smart reader noticed that the works as designed construct is flawed. If this is the case, then my proof worked as specified.
P.S. If I were the client, I'd only sign contracts that say the software vendor must ship works as intended software.
And now I'm questioning if the construct is correct. How much sense does design make to a tester? And considering that some teams have this open policy where clients can see all the product bugs, how much sense does design make to a client?
To find out the answer, try this: in UAT, go to your client and tell her that the bug she thinks she found is actually the behavior as designed. Don't be surprised if she asks you What design? Now if you are smart you'd shut up and go check the spec that she counter-signed, if you are not-so-smart (read stupid or inexperienced) you'd say: What design?! The UML class design, the interaction and ORM diagrams!
By now the smart reader noticed that the works as designed construct is flawed. If this is the case, then my proof worked as specified.
P.S. If I were the client, I'd only sign contracts that say the software vendor must ship works as intended software.
Subscribe to:
Posts (Atom)
