Saturday, October 25, 2008

[Blogger] How to dinamically change Blog Title

You can dinamically change your Blogger Blog title to whatever you want (in this case you're changin it into 'NEW KICK-ASS TITLE') using the following Javascript snippet:


var myKickAssScript = "document.getElementById('header-inner').getElementsByTagName('h1')[0].innerHTML = 'NEW KICK-ASS TITLE'";
setTimeout(myKickAssScript, 2000);



We have to set a timeout in order to wait for the title element to be injected by the blogger engine. You can put this js code in the script element that's in the head section of the markup (you can edit it from 'edit HTML' section on your blog settings). 
If you put the snippet (passed as string to the timeOut function above) at the bottom of the page (or as event handler for the onLoad event) you obviously don't need to set up a timer.


It'll work as long as they decide to keep the page markup as it is now.

P.S. check-out my NEW KICK-ASS TITLE

Friday, October 24, 2008

[C++] convert std::string to const char * (and back)

Kind of a lousy-ass post but Straight to the point (with UNICODE on):

#include <string>
using namespace std;

//..

//from std::string to const char*
string originalStr("Bunny Colvin Kicks Ass");
const char* cnstCharPtr = str.c_str();

//the other way around
string convertedStr(cnstCharPtr); //as simple as this
 
I found myself googlin' this up a number of times and I always forgot everything soon enough since I don't use it often. I decided to post it as a reference for myself and to increase chances to find an answer for anyone else who might be looking for it.

Cheers

Wednesday, October 22, 2008

The Unmentionable NECRONOMICON of WinApps (BAD Code is Language Independent)

I am working on a MFC app internally referred as the unmentionable NECRONOMICON of WinApps. This thing is a dying beast composed by an indefinite number of dlls: it seems put together as an ad-hoc example of the so-called DLL HELL. It compiles and builds by magic and by magic only. The thing is so scary no-one ever attempted touching it for 7 years or so. There are stories about the last guy who tried to fix a few bugs: he went crazy and left the company with no reason (OK, he just left the company). 

Anyway, most of this thing is coded in C++ and MFCs (except a bunch of cryptic COM components in VB6 and stuff which hopefully I'll never have to touch).  After having a thorough look at the code I can say that YES, the app is way far from being mainteinable, but - surprise - it's not because of C++. Same stuff written in C# would scare eggs out of (SCRUM) chickens.

Loads of people seems to hate C++, because it's error-prone (...), verbose, kinda cranky and not that cool anymore. Most of them probably don't even know about copy-constructors and destructors otherwise they'd hate C++ even more. I agree with most of this complaints and no-one would ever dream of developing a brand new WinApp today using MFCs. We got away from that and now we can focus on making cool apps, not just "working" ones.

Getting to the point, the fact that C++ apps do not write themselves seems to be ignored - people tend to forget one of the basic laws of programming: BAD code is language independent.

P.S. Wish me luck, I need it

Sunday, October 19, 2008

Software Development Methodologies Zoo


[Waterfall - 1970]
The waterfall model is a sequential software development process (...) in which development is seen as flowing steadily downwards (like a waterfall) through the phases of requirements analysis, design, implementation, testing (validation), integration, and maintenance.
You can't stop a waterfall - meaning that if you're in the middle of a project and requirements change ... well ... let's say you're in troubles.


[V-Model - late '80s]
The V-model is a software development process which can be presumed to be the extension of the waterfall model. Instead of moving down in a linear way, the process steps are bent upwards after the coding phase, to form the typical V shape. The V-Model demonstrates the relationships between each phase of the development life cycle and its associated phase of testing.



This is a zombie model, it's dead but plenty of ISO and CMM fanatics out there think V-Model is still pretty cool. V-Model is indeed a very good methodology for high-ceremony organizations for its ability to give management a sense of false security.


[Cowboy Coding - wild west]
Cowboy Coding is a term used to describe software development where the developers have autonomy over the development process. This includes control of the project's schedule, algorithms, tools, and coding style.

In an ideal world, this would be my favourite. Whenever I start my own company I am pretty sure I'll adopt and formalize Cowboy Coding [yippy kayay!].

[SCRUM - early '90s]
Scrum is an iterative incremental process of software development commonly used with agile software development. (...)
Scrum is a process skeleton that includes a set of practices and predefined roles. The main roles in Scrum are the ScrumMaster who maintains the processes and works similar to a project manager, the Product Owner who represents the stakeholders, and the Team which includes the developers [chicken and pigs!].
During each sprint, a 15-30 day period (length decided by the team), the team creates an increment of potential shippable (usable) software. The set of features that go into each sprint come from the product backlog, which is a prioritized set of high level requirements of work to be done.


Conceptually born in early '90s, SCRUM started being widely adopted 10 years later. It's like the model farm of AGILE software development with ScrumMaster to coordinate chicken and pigs. All you need to know is pigs do all the work.

[ICONIX - late '90s]
ICONIX is a software development methodology which predates both the Rational Unified Process (RUP), Extreme Programming(XP) and Agile software development. Like RUP, the ICONIX process is UML Use Case driven but more lightweight than RUP. Unlike the XP and Agile approaches, ICONIX provides sufficient requirement and design documentation, but without analysis paralysis. The ICONIX Process uses only four UML based diagrams in a four step process that turns use case text into working code.
A principle distinction of ICONIX is its use of robustness analysis (...). This process makes the use cases much easier to design, test and estimate.

ICONIX basically combines an AGILE approach with a robustness oriented low-ceremony design. This Process carries the strictly necessary amount of weight to still ride fast. This is the process I use at the moment, you can read more about it on this post.

[Extreme Programming - XP]
Extreme Programming (XP) is a software engineering methodology prescribing a set of daily stakeholder practices that embody and encourage particular XP values. Proponents believe that exercising these practices—traditional software engineering practices taken to so-called "extreme" levels—leads to a development process that is more responsive to customer needs ("agile") than traditional methods, while creating software of better quality.
Proponents of Extreme Programming and agile methodologies in general regard ongoing changes to requirements as a natural, inescapable and desirable aspect of software development projects; they believe that adaptability to changing requirements at any point during the project life is a more realistic and better approach than attempting to define all requirements at the beginning of a project and then expending effort to control changes to the requirements.
XP is all about speed, and we all like speed if it means no documentation. Biggest drawbacks of this approach may be problems like feature creep and scope creep - moslty due to lack of persistent reference.

Thursday, October 16, 2008

[SSIS] How to remotely run a DTSX package from bat file?

Short answer (or at least the conclusion I came to after a fair amount of research  - and plenty of hair pulling): you can't .

Long Answer: I started from this cmd, which works like charm locally:


DTEXEC /DTS "\File System\MY_PACKAGE_NAME" /SERVER MY_SERVER_NAME /MAXCONCURRENT " -1 " /CHECKPOINTING OFF /REPORTING V


If you try to use the same cmd remotely it will miserably fail with some nasty timeout.

After a bit of googling it looks like it is impossible to run DTEXEC cmd remotely (it needs to be run locally - remote execution apparently is not supported).

To overcome this limitation the following method seems to be broadly implemented:
  • set up a SQL job to run the DTSX package
  • set up a Stored Procedure to run the job
  • use isql command line in a BAT file (remotely executed) to run the stored procedure on the relevant SQL instance (with SQL credentials and not machine credentials)
Might work - but kinda sucks.

Wednesday, October 15, 2008

[.NET] Why are Exceptions not Checked in C#?

Going from Java to C#, I've been stunned by the absence of  the "throws" clause in the declaration of a method, in which you want to throw a particular exception.
Actually it hasn't caused me so much pain, but the knowledge at compile time of the possibility that an exception could be thrown sounded very useful to me.
Asking to the StackOverflow community, I found out Java is one of the few programming languages where exceptions are "caught" at compile time.
The philosophy behind C# is that what is useful about exceptions is not handling them, but mostly cleaning resources, implementing the IDisposable pattern (The trouble with Checked expcetions).
If you know that a particular method can throw an exception, you also know what it does and how to handle it, otherwise you will handle a generic exception, without need to specify it at compile time; moreover handling exceptions is something that comes near the caller of a method reather than the method itself, so there is no need to specify a chain of "throws" declarations, and that is so useful in versioning, because adding a new exception (or removing an old one) doesn't require a refactoring of your lib.
It is worth noting that C# supports the <exception> tag in the documentation section, with which the compiler informs you that an exception (whose type is anyway checked for existence) can be thrown, without any further constraints.
If you have other issues or different opinions I'd like to hear them.

Good butchering!

Friday, October 10, 2008

ICONIX Process Rocks

Today we talk about my favorite software development process, so-called ICONIX.
This should probably give an answer to the few dinosaurs who like going around saying that AGILE is an excuse for not having a well-defined process (they probably think the V-Model still rocks - good lads).

ICONIX adopts a subset of core AGILE techniques and it is a behavioral requirements (Use Cases) driven process. The ICONIX process aims to be as low-celebration as possible carrying as little documentation as possible through iterations - in order to allow you to easily keep it up-to-date (this is a big difference from other AGILE processes, as XP, which aim at carrying no documentation at all).
For fans of TDD (Test Driven Development), it has been proved that ICONIX can be easily paired with the latter: http://www.springerlink.com/content/k15l318vq1013057/

Here's a practical overview of the process:
  1. Quick Draft of Functional Requirements (in theory throw-away)
  2. Quick Definition of a Domain Model (identify entities and classes)
  3. Model Use Cases on the base of previous steps (This is what drives development)
  4. Draw a throw-away robustness diagram for each use case (to understand relations between your classes)
  5. Draw a Sequence Diagram for each use case (here you'll understand which methods you really need)
  6. Model your test-cases on the use cases
  7. Implement
  8. Test
At each step you review your work as a whole updating your domain model (it's impossible to get it right first time) and adding comments on your use cases. By the end of step (5) you end up with ready-to-implement classes and logic with just little documentation to maintain if you re-factor or change anything. The following is indeed the only documentation you need to carry through iterations:
  • Use case diagram
  • Sequence Diagram for each use case
  • Test case diagram (or test plan)
If you need to add features, you add new use cases and follow the whole process.
 
In my experience the ICONIX process works regardless of the size of the project. In a medium-large project you just split the implementation of features in short iterations in an AGILE fashion. It is worth underlining that the big difference between most extreme AGILE processes and ICONIX is that you do keep documentation up-to-date, you don't just throw it away after each iteration. This is possible because the process aims (again) at keeping very light-weight documentation.

Thursday, October 9, 2008

[JAVA] Calendar Months Start from Zero

I don't have time to make a big deal out of this but please tell me which month is the 12th one in the year. I was so stupid to think it was December. Thanks to the JAVAAPI guys I got enlightened. The 12th month is Janaury cause the count starts from 0, it goes to 11 and then starts over again. Grand job to the java.util.Calendar guy!

Thursday, October 2, 2008

[.NET] How to Programmatically Create and Access Custom ConfigurationSections

.NET app.config and web.config are powerful instruments to store simple key value pairs and connections strings.When you need to store config data in some specific format and key value pairs are not enough you can use Custom Configuration Sections as they are not complex to use (unless you need a fairly complex section):

1) Define your custom section:

public class CustomSection : ConfigurationSection
{
[ConfigurationProperty("LastName", IsRequired = true,DefaultValue = "TEST")]
public String LastName
{
get { return (String)base["LastName"]; }
set { base["LastName"] = value; }
}

[ConfigurationProperty("FirstName", IsRequired = true, DefaultValue = "TEST")]
public String FirstName
{
get { return (String)base["FirstName"]; }
set { base["FirstName"] = value; }
}

public CustomSection()
{

}
}



2) Programmatically create your section (if it doesn't already exist):

// Create a custom section.
static void CreateSection()
{
try
{

CustomSection customSection;
// Get the current configuration file.
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(@"ConfigurationTest.exe");

// Create the section entry
// and the
// related target section
if (config.Sections["CustomSection"] == null)
{
customSection = new CustomSection();
config.Sections.Add("CustomSection", customSection);
customSection.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
}
catch (ConfigurationErrorsException err)
{
//manage exception - give feedback or whatever
}

}



Following CustomSection definition and actual CustomSection will be created for you:

<configuration>
<configsections>
<section name="CustomSection" type="ConfigurationTest.CustomSection, ConfigurationTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" allowlocation="true" allowdefinition="Everywhere" allowexedefinition="MachineToApplication" overridemodedefault="Allow" restartonexternalchanges="true" requirepermission="true">
</section>
</configsections>
<customsection lastname="TEST" firstname="TEST">
</customsection>
</configuration>


3) Now Retrieve your section properties:

CustomSection section=(CustomSection)ConfigurationManager.GetSection("CustomSection");
string lastName = section.LastName;
string firstName = section.FirstName;


This is all good stuff - nice and easy as you can see.

P.S. This post orginally appeared on this  StackOverflow link, but since I wrote it I thought it would do no harm to recycle my own rubbish here.


kick it on DotNetKicks.com