Friday, October 24, 2008

No Microsoft, It wasn't you!!!

It wasn't you who discovered the benefits of multi-tire applications, no, it wasn't you who discovered the wonders of using namespaces to logically organize what you call types, and the rest of the world call classes, interfaces, and so on.

These days of financial crisis I'm reading a book about ASP.NET. The book isn't bad at all, but is somehow Microsoft biased. Written by a bunch of MS MVPs (Most Valuable Professional) is not difficult to understand that the authors must keep the big brother happy. But sometimes is so much, that it feels like a comedy book. I'll give you some examples:

1.- Microsoft forget easily: This book criticize merciless the classic ASP model. Well, I still remember how they sold us this cutting edge, flawless technology. Not only classic ASP was a total crap, but now M$ have found the way to make our life easier: fully object oriented server side code, and compiled, Ohhhhhh thanks M$, Thanks for delivering what Java gave us almost 8 years ago, thanks anyway for the laugh.

2.- Microsoft have discovered that mixing presentation and logic isn't good: This is absolutely hilarious. Microsoft have discovered 2 years ago, a principle of Software Engineering that has been with us, software engineers, for almost 10 years now, if not more. It was about time lads!!!.

3.- The most amazing, namespaces: .Net organizes classes into logical units called namespaces!!!!!!!!!!!! WTF at this point I though maybe I was drinking poisoned water. How is this possible, even the most M$ biased programmers now that namespaces have been around for about 20 years now. Of course the horrible Win32 API don't now much about this, but this is no reason to say that one of the wonders of the .NET framework (which I think is a good thing) are namespaces. I will put this in another way, .NET without namespaces would be absolutely pointless.

Well, I could continue for hours, but I think it's enough for today. I hope you have laughed reading this as much as I'm reading that ASP.NET book.

Maybe I'll give the book's title in a future post.

Enjoy life lads!!!!

Labels: ,

Thursday, October 16, 2008

Multithread programming

Multi-threaded programs are a must in a world dominated by servers, GUI applications, multiprocessor computers and so on. The standard way of managing threads is by using POSIX threads. I've found and amazingly easy to follow article about POSIX threads. It's only recommendable for those of you who already have knowledge of the basic thread mechanisms and OS design:

Multi-Threaded Programming With POSIX Threads

Examples are written in plain old marvelous C, so it might be hard to understand for the Java, and C# crowd, but lads, this is real software!!! :)

Here you have a little example using threads, it's not rocket science, but makes the job:


#include
#include
#define LIMIT 100

/* prototype of the function that will be executed by a
thread. It's compulsory to return a void * and to receive
a void * as the only parameter */
void * do_loop(void * arg);


int main()
{
/* The thread to be created */
pthread_t MiThread;
/* We will use these two as parameters to do_loop */
int th1 = 1;
int th2 = 2;
/* Will get the return value of pthread_create(...) */
int rc;
printf("Starting application\n");
/* Actual thread creation. Parameters:
1st .- The thread to be initialized
2nd .- Configuration parameters, NULL to use default
3rd .- The function to be executed by the thread
4th .- The parameter to be passed to do_loop
*/
rc = pthread_create(&MiThread,NULL,do_loop,(void *)&th1);
/* The main thread also executes the loop, to show us the intermixed
execution of both threads */
do_loop((void*)&th2);
/* Just in case, the main thread waits for the auxiliary thread to
finish */
pthread_join(MiThread,NULL);
system("PAUSE");
}

void * do_loop(void * arg)
{
int i = 0;
for (i = 0 ; i < LIMIT ; i++)
printf("Hello Thread %d\n",*(int *)arg);
return NULL;
}



By the way, there is a companion article that gives an introduction to parallel programming. Interesting for the newbie.

Parallel Programming - Basic Theory For The Unwary

Enjoy!

Labels: , ,

Tuesday, October 14, 2008

ASP.Net Datagrid control

Hi lads,

Slowly but steadily I'm discovering the goods and bads of ASP.NET programming. On the one hand it's pretty simple to make a simple but rather functional web application, on the other hand the programming model, if any, it's really simplistic, and this is good, but also bad. On top of that there aren't billions of frameworks to use, in contrast to the Java world, that makes things easier, but also gives you less power. Other factors are the insane dependency on Microsoft, slave forever of IIS, that is definitely not good. Ahh, and don't forget you can program almost everything using very simple HTML and C#, this last one is becoming my favourite language, after god C++, of course.

Well, one very powerful web control provided by ASP.NET is the Datagrid control. It basically allows to show information in a table. This information must come to any source that implements the IEnumerable interface. All the dirty HTML code is automatically generated by ASP.NET, and this, for those of you who fought with the old classic ASP, is a blessing.

I have found a couple of good articles and web sites about the use of this Datagrid web control, I hope they are useful for you.


Enjoy!!!!!!!

Labels: , ,

Saturday, October 11, 2008

Mono 2.0 Use .NET out of Windows

Since .NET assemblies compile down to CIL bytecode that's executed in a virtual machine under Windows, there's no reason, in principle, that they shouldn't be able to run under any platform. After all, Java's "write once, run anywhere" mantra has the same fundamental architecture: a VM running bytecode that taps into a series of standard APIs and classes.

Labels: , ,

Thursday, September 25, 2008

Friend Classes (strange justification)

I'm not a friend of the C++ friends, whether they are functions, member functions or classes. However there are some situations when the use of a friend function can be somehow beneficial, like making the operator << compatible with a particular class (although it's possible to just override or create a kind of toString() method, like in the best Java flavour).

Lately I've been reading a book on C++ programming. This book is intended to be read by novices, and because of that I think the author should have been more careful when giving advices. This is the way the author justifies friend classes:

"When might you want to make one class a friend to another? Let’s look at an example. Suppose you must program a simple simulation of a television and a remote control. You decide to define a Tv class representing a television and a Remote class representing a remote control. Clearly, there should be some sort of relationship between these classes, but what kind? A remote control is not a television and vice versa, so the is-a relationship of public inheritance doesn’t apply. Nor is either a component of the other, so the has-a relationship of containment or of private or protected inheritance doesn’t apply. What is true is that a remote control can modify the state of a television, and this suggests making the Remote class a friend to the Tv class."


This is exactly the example my teachers at university used to teach as an event broadcast pattern like Observer, which is by far a better solution.

Friend classes completely break encapsulation, and couples classes so tight that it will be impossible to use one without the other, therefore preventing code reuse.

The book is called "C++ Primer Plus, Fifth Edition".

Labels: ,

Wednesday, September 10, 2008

Programming cheat sheets

Either if you are a novice or an experience programmer it's always a good idea to have at hand one cheat sheet that helps  you not to make the most usual syntax mistakes. Here you have a compilation of different programing languages' cheat sheets:


Enjoy!

Labels: , ,

Sunday, August 31, 2008

Perspective projection

I've always been interested in Computer Graphics. This area of computer science unites most of the things I´m interested in. From pure maths to algorithm analysis, and software engineering, if you want to be a good graphics programmer, you need to master of this fields of knowledge.

The purpose of this post is to provide a set of interesting links about perspective projection. This concept is absolutely essential to understand modern graphics, especially 3D game graphics. Thanks to APIs like OpenGl or DirectX, you don´t have to program your own projection, but you need to understand what is going on under the hood to be able to make the most out of it.

Enjoy!!!


Labels: ,