TechnicalArchitectureWorx

The (Unofficial) ITWorx Technical Architecture Blog

Archive for the ‘Programming’ Category

Developing Reusable .NET Components

Posted by archworx on June 10, 2007

Hello All,

I have been developing Custom ASP.NET Server Controls for a while now and I think it is worthwhile to write a series of blog posts about how to develop them. So here we go with the first introductory blog. First, let us think why developing .NET components is important. Well, first of all Microsoft has developed a decent set of components and controls for the .NET framework, but surely these preexisting components don’t fit every scenario that you might need when you are developing your application, so this is why creating new components (or extending existing ones) is needed. More importantly it is the concept of reusability that particularly makes developing such components useful. Identifying certain recurring scenarios and common functionalities and developing a certain component that can be reused by yourself and others without having to re-write the same code again is very valuable. A friend of mine has recently told me that “A good developer only writes code once”. This proverb, albeit an oversimplification, captures the essence of reusability. Great, so what implications does this have on you as a developer? Well, being able to capture repetitive scenarios into reusable code is very important. So next time you write code try to think if you have written this code before (or if you are going to write it again in the future) and if so then you can try to encapsulate it into a component that can be reused (even if this means creating a simple code snippet). This doesn’t only apply to code that you write, but if you are smart enough you can identify recurring patterns inside applications that your organization is developing and hence suggest how reusable components can be used within the company to improve the development process. So, with this introduction over we will turn to talking about Custom Controls in .NET and how they differ from User Controls. But alas, this will have to wait till the next blog.

Posted in .NET 2.0, AFathalla, Programming, Reusable Components | Leave a Comment »

Edit and Continue

Posted by archworx on May 23, 2007

Source: http://msdn2.microsoft.com/en-us/library/bcew296c(VS.80).aspx

Edit and Continue is a time-saving feature that enables you to make changes to your source code while your program is in break mode. When you resume execution of the program by choosing an execution command like Continue or Step, Edit and Continue automatically applies the code changes with some limitations. This allows you to make changes to your code during a debugging session, instead of having to stop, recompile your entire program, and restart the debugging session.

Posted in .NET 2.0, El-Geish, Programming, VS 2005 | Leave a Comment »

F#

Posted by archworx on May 23, 2007

Source: http://research.microsoft.com/fsharp

Combining the efficiency, scripting, strong typing and productivity of ML with the stability, libraries, cross-language working and tools of .NET.

F# is a programming language that provides the much sought-after combination of type safety, performance and scripting, with all the advantages of running on a high-quality, well-supported modern runtime system. F# gives you a combination of

The only language to provide a combination like this is F# (pronounced FSharp) – a scripted/functional/imperative/object-oriented programming language that is a fantastic basis for many practical scientific, engineering and web-based programming tasks. 

F# is a pragmatically-oriented variant of ML that shares a core language with OCaml. F# programs run on top of the .NET Framework. Unlike other scripting languages it executes at or near the speed of C# and C++, making use of the performance that comes through strong typing. Unlike many statically-typed languages it also supports many dynamic language techniques, such as property discovery and reflection where needed. F# includes extensions for working across languages and for object-oriented programming, and it works seamlessly with other .NET programming languages and tools.

For further information, read about F# in more detail, download the F# distribution, read the getting started pages (a guide to installation and running your first program), go to the F# Manual, and learn about the growing F# Community. A short FAQ is also included on this site.

Some Starting points

Posted in .NET 2.0, El-Geish, Programming | 1 Comment »

Anonymous Methods in C#

Posted by archworx on May 23, 2007

In .Net v1.x, declaration of delegate required named methods. C# 2.0 introduced anonymous methods, as MSDN states, “Creating anonymous methods is essentially a way to pass a code block as a delegate parameter.

// Create a handler for a click event
btn.Click += delegate(System.Object o, System.EventArgs e) { MessageBox.Show("Click!"); };

This can be very useful in some cases such as a parameter to the Thread constructor:

new System.Threading.Thread(
  delegate()
  {
      System.Console.WriteLine("Hello");
      System.Console.WriteLine("World");
  }).Start();

Click here for more info.

Posted in .NET 2.0, El-Geish, Programming | 1 Comment »

‘My’ Namespace in VB.Net 2.0

Posted by archworx on May 23, 2007

For rapid development, Visual Basic .Net 2.0 introduced a namespace called My to access all the stuff that belongs to you like computer, network, printers, keyboard, forms, and others.

My Namespace 

For eaxmple, if you need to access the network, you just type: My.Computer.Network.

If My.Computer.Network.IsAvailable Then
    My.Computer.Network.DownloadFile("http://myserver.com/log.txt","c:\archives\serverlog.txt")
End If

Click here for more info.

Posted in .NET 2.0, El-Geish, Programming, VS 2005 | Leave a Comment »

Considerations for Securing Log-in?

Posted by archworx on April 18, 2007

Someone was asking us about what factors to consider in order to develop a “secure” log-in component. Off the top of my head, I could think of the following rules of thumb that you should honour, assuming 1-factor security:

1. You really should communicate over SSL

2. You should also never transfer any credentials in the query string (neither username, nor password, nor any token of any sort)

3. Also, make sure that the password is never stored in plain text in your data repositories – you must always store its hash generated using a one-way hashing function. Being one way means that you can never go back the other way and retrieve the plain text password from the hash.

This means that you can never retrieve the password from the hash, so in order to verify it, you must take the newly provided password and hash that too, then compare both hashes to verify if they are identical. You can never do the comparison based on the plain-text of the password itself.

This is important because it illimates the risk that the admin will be able to find out what the plain-text password is by reversing the encryption function. From an algorithmic perspective, it is not acceptable to just “rely on the trustworthiness of the administrator” 🙂

4. At the same time, it is recommended that you use a “salt” to encrypt the password, or some other strong form of encryption.

I’m sure there may be others, but I can’t think of any more now – What else should we look for? 

Posted in Interview Question, mkaram, Programming, Security | 3 Comments »

Personal Capability Maturity

Posted by archworx on February 11, 2007

So I’ve been thinking about classifying candidates for interviews, or even team mates and colleagues at work according to their capability, for some time.

Disclaimer: Before you go on – please note this isn’t to establish workplace supremacy, but instead to enhance communication between team members!

Sometimes you’re sitting there talking to someone who seems to be spewing out jargon without really understanding what the underlying implications are. Other times you can discuss a topic with someone and find out that they’re trying to convince you of a solution that is so advanced you can’t readily grasp it!

So I’ve come up with the following theoretical model to classify people according to their vocational performance. I think this kind of classification is very important for each and every one of us. This isn’t so we can gain fake karma points or establish supremacy of any sort; but instead to know where one stands and what challenges you need to overcome in order to advance your career. This goes back to the post about reverse-engineering success, if you still remember that.

It is also important that you consider this model in terms of how to deal with co-workers. The most important aspect of industrial development is team work. A team can never work with dysfunctional communication, so you need to use this measure all the time in order to use the right tools to communicate with different calibres within your team. If you don’t immediately identify your team-mates specific capability at the start of a conversation you risk wasting the time the rest of it is about to take.

Back to the theoretical model I was talking about earlier, let me take you through its different levels, and we’ll be getting back to this every now and then as we work with answers to interview questions, and find out where the proper balance between pragmatism and ingenuity is achieved.

Here is the model – keep this in the back of your head the next time you work on a technical puzzle; I will call this the “Mkaram Intellectual Capability Model”, blatantly stealing prevalent industrial nomenclature (thank you CMU/SEI/DoD):

  • Level 0 – This is when you are totally stumped, you have no clue, and you can’t even start to address the question
  • Level 1 – Someone asks you a question and you start babbling for a few seconds, being mostly incoherent for some time until finally starting to mildly approach the problem with a mediocre solution that may be buggy or stands a marginal chance of working
  • Level 2 – You are asked a question, which may or may not take you a minute to think of, but you end up giving a perfectly functional framework for a solution that will work, and will do so elegantly
  • Level 3 – You give the question a moment of thought, and either leverage powerful solution patterns that you know inside out by virtue of how well you’ve worked with and thought of them previously, or challenge yourself to come up with clever shortcuts (because you know innately that they almost always exist for every problem). In either case your end solution is not only perfectly functional, but also covers new ground in terms of efficiency, elegance or otherwise.

If you combine this theoretical model with the 80/20 rule, that only 20% of your work is where 80% of the most critical application time is executed, then you should work as hard as possible to make sure your baseline never goes below Level 2 (or change your industry), and in fact, continuously push yourself towards Level 3.

As an extension to the disclaimer above, note that these levels are dynamic and relative, instead of absolute. Your own personal level can vary greatly according to how well you know your turf!

Posted in Interview Question, mkaram, Programming, Rant | Leave a Comment »

Interviewing Question: How can I randomize without recurrence?

Posted by archworx on February 6, 2007

Suppose I have an application that plays the audio files on my play list, and supports playing them in a random order. More often than not, this kind of application will employ a Psuedo-Random Number Generator. Which is great, except that these kinds of generation algorithms tend to be not exactly random sometimes. This becomes a problem when the algorithms are so bad that starvation occurs. With starvation you get some tracks that are played over and over again, and others which are almost never played. One way to fix this is by further warping the “randomness” of the Psuedo-Random sequence to try to make sure that every track is played once and only once before it is ever replayed.

How would you implement this in code, as a first hack?

How would you implement this efficiently?

Posted in Interview Question, mkaram, Programming | 6 Comments »

Book about Creating and Manipulating PDF

Posted by archworx on November 29, 2006

In iText in Action: Creating and Manipulating PDF, author Bruno Lowagie walks through everything PDF, Adobe’s Portable Document Format, from a Java developer’s point of view. Lowagie covers how to use iText in a Java/J2EE application for the production and/or manipulation of PDF documents. Along the way, Lowagie describes interesting PDF features and explains more obscure e-document functionalities. In addition to many small code samples, this book includes XML-based, ready-made solutions that can easily be adapted and integrated into projects.

There is a sample chapter titled “PDF: why and when“. The first section of this chapter explains why PDF was invented and how it evolved into a de facto standard. In the second section, Lowagie describes the different PDF “flavors,” some of which are described in an International Standards Organization (ISO) standard. Lowagie uses a table listing different versions of the PDF specification to focus on specific features such as compression and encryption. He also uses “Hello World” examples to show how to compress/decompress and encrypt/decrypt PDF files.

Posted in Java, Nader, Programming | Leave a Comment »

How to create a Vista Sidebar Gadget.

Posted by archworx on November 5, 2006

I was asked to create a quick POC (proof of concept) for a MS Windows Vista sidebar gadget. I did the usual Live.com search and discovered a few posts.

An interesting post was by a guy called Daniel Moth. It had lots of useful information, but unfortunately it just didn’t work for me. There seems to be something missing in the xml file accompanying the gadget, as well as some rubbish text in the file, so your gadget won’t work but you won’t get an error.

I found a more uptodate sample on MSDN. This was also on Daniel Moth’s blog, so many thanks to him.

Now here is my version of the hello world sidebar gadget.

Step 1:

Create the following HTML file:

<html>
<head>
 <title>Hello, World!</title>
 <style>
  body {
   width:130;
   height:50;
  }
 </style>
</head>
<body>
 <span id=”gadgetContent” style=”font-family: Tahoma; font-size: 10pt;”>Hello, World!</span>
</body>
</html>

Call it HelloWorld.html

Step 2:

Create the following XML file:

<?xml version=”1.0″ encoding=”utf-8″ ?>
<gadget>
    <name>Hello World!</name>
    <namespace>Example.You</namespace>
    <version>1.0</version>
    <author name=”Your Name”>
        <info url=”
www.example.com” />
    </author>
    <copyright>2006</copyright>
    <description>My first gadget</description>
    <hosts>
        <host name=”sidebar”>
            <base type=”HTML” apiVersion=”1.0.0″ src=”HelloWorld.html” mce_src=”HelloWorld.html” />
            <permissions>full</permissions>
            <platform minPlatformVersion=”0.3″ />
        </host>
    </hosts>
</gadget>

Call this file Gadget.xml

Step 3:

Create a folder called Helloworld.Gadget

Step 4:

1.Simply copy”%userprofile%\AppData\Local\Microsoft\Windows Sidebar\Gadgets” and paste in Windows explorer address bar.
2. When you get to that folder Copy and Paste the “HelloWorld.Gadget” folder there.

Step 5:

Add the gadget to your Sidebar and your done !

That’s how easy it was to create a sidebar gadget. Obviously, you want your gadget to do more than just display “HelloWorld”. You have infinite possibilities. Anything that con be done with DHTML or .NET can be done on a sidebar, you just have to make sure you have the right permissions.

How do I create a gadget with .NET?

If you check out the MSDN link you should find it there, and if I get something done soon, I’ll surely post it.

Also check out the Gadget team blog.

Anyway, that’s it for now, Happy developing!

Posted in MSamy, Programming, Vista | 351 Comments »