Saturday, May 29, 2004

To be or not to be virtual

It's interesting to see how languages look at a specific design decision in different ways. I'm of course talking about the Java, C# and C++. In particular, the case of virtualness.

Java, by default, makes every method of a class virtual by default. You need to explicitly specify if you DON'T want to make it overridable by using the keyword "final". C# goes the C++ way in making every method non-virtual by default.

Why did the designers choose to do it differently? From Java's perspective, I assume they were thinking about extensibility. So if the class doesn't do what you want exactly, you can always derive and add your own functionality. This affords you with some leeway in the design. If you feel like something is not right after the initial phase, you can always go back and make changes. On the other hand, you get good performance with C# and C++ cause the function calls are static - no indirection.

What do you think? Which dyou prefer? I guess this is a grey area like pretty much everything in software design. There are always tradeoffs. I guess there is no "right" answer here.

I personally feel that C#/C++ is the better option. Not only for the performance reasons, but also because the class designer is in complete control. You decide how much extensibility you want your class to have. You can make sure that your class will not be used for something it was not meant to be. Yeah, you can do the same in Java too, but it takes more code, even if it is only one extra keyword. Most functions in classes will NOT have the "final" keyword on them. C#/C++ might even make you think about design harder since it's sort of set in stone once you release. With Java there might be a tendency to think like "oh, we can always derive and change later if something's not right".

Wednesday, May 26, 2004

Re: Stack

I've read that the heap is implemented as a linked list sort of data structure

Even I have read about this. It must be interesting to find out exactly how it's modelled.

I understood the 3rd object file as being akin to the DLL. The process image pertains to the actual program after being loaded into the memory. If you want more information about all this go here

I got the info about the object files from there.

dinesh.

Re: Coder to Developer

This exact same argument can be applied to the Windows, Office and IE monopolies. Who is forcing you to use it?

The point is that once people get used to something and find it reasonably good, that satisfies their needs, they are reluctant to change.

Exactly my point. No one's forcing me, I use it because it serves a definite purpose for me, once it stops serving that purpose, I move on. What I don't whine about is the company not complying to my needs. If I disagree with something about the product I have a choice not to buy it, but I can't force the company to sell it my way. Thats not an option in a free society. My need cannot be claim on a company owned by someone. He is free to run it as he sees fit.

dinesh.

Tuesday, May 25, 2004

Re: Stack

Great informative reply.

I guess I sort of confused the stack memory allocation with the allocation of variables in the program. For some reason I read the quote as saying that when the program is run, all the stack variables in the program will be allocated and initialized. That's obviously not what it meant. I guess it's the act of reserving memory for the stack and the book keeping like initializing the stack pointers, frame pointers etc...

I am not sure as to what happens exactly happens, when say new is used. The object created, is created on the heap, but maybe it is accessed through a pointer to it's memory address, stored somewhere locally by the operating system. Just check this out, not sure how it's implemented in C++.

Well, when you use "new", you get back the address of the object created on the heap. Generally you store that address in a local pointer variable, which is stored on the stack. I dunno if this was your doubt.

I suppose the big difference between the stack memory and the heap (free store) is that allocation on the stack takes constant time (its just a pointer increment and constructing) whereas allocation on the heap is not necessarily constant. It needs to find a large enough space to be able to hold the object. I've read that the heap is implemented as a linked list sort of data structure. Dyou know anything about this?

There are three main types of object files.

Great info again. I didn't realize there were different types of object files. I just thought after you compile, you get a .obj file and after you link you can a .exe. Could you elaborate on #3 a bit? I didn't understand what the dynamic linker was.

I sometimes think that to be a true great when it comes to C/C++, one has to have some compiler design experience, then only you can truly know all the small nuances associated with this language.

I feel like it's more curiousity than anything else. As in, I have this concept of a stack in my mind, but how exactly does it all come together? Also, how does the system find a large enough free space on the heap for allocation. This is all good to know info and I find it interesting, but you don't particularly need to know it to be productive with C++. But as you say, to be "great", yeah, that's a different story. Knowing the guts of how the system works is critical.

I think having a good background in OS would help a lot especially when it comes to memory issues cause it's the OS setting up everything. I agree with you regarding knowing what the compiler is doing. It might be pretty worthwhile to play around with the CFront compiler which compiles C++ code to C. Stan Lippman uses this technique in his book "The C++ Object Model".

Re: Coder to Developer

Google is a non-coercive monopoly, so let them enjoy it. They certainly deserve it. In a non-coercive monopoly, people always have the choice not to make use of a service. No one's "forcing" people to use google, it just got that way because they are good.

This exact same argument can be applied to the Windows, Office and IE monopolies. Who is forcing you to use it? You have plenty of choices out there - All the *nix's, Mac, Open Office, Star Office, WordPerfect, Mozilla, Opera, Safari etc... Don't like Microsoft? You can get by fine without using them. Interoperability is becoming less of an issue everyday with competing products being able to read and produce MS file formats.

The point is that once people get used to something and find it reasonably good, that satisfies their needs, they are reluctant to change.

Monday, May 24, 2004

Re: Stack

"The static storage area is simply a fixed patch of memory that is allocated before the program begins to run. Using the stack or static storage area places a priority on the speed of storage allocation and release, which can be valuable in some situations."

What does "allocated before the program is run" mean exactly? Does it just mean that the OS "reserves" some area of memory and uses that as a stack (keep pushing on the function calls etc... in this area) in a FILO manner? Whereas the heap is just another chunk but you are free to allocate anywhere.


I think the answer to your queries lies in reading up on segmentation. When segmentation is used, a program which has been loaded, is allocated different segments for different parts of it.

In it's most basic sense say a program gets three segments 1) Program Instructions 2) Data 3) Call Stack. This was the basis for bring forward segmentation, so that we could get rid of the 1-D paging systems. In the 1-D system, the program, data, stack et al fall on a single piece of contiguous memory, so things could cram up when they grow. Now going back to segments, the program mentioned earlier, would have say the following segments.


| | | |
| | | | | |
| | | | | |
| | | | | |
Segemnt1 Segment2 Segment3
Program Data Call Stack


So yes, the local data in main() for a C/C++ program does get allocated when the program is loaded in memory. I am not sure as to what happens exactly happens, when say new is used. The object created, is created on the heap, but maybe it is accessed through a pointer to it's memory address, stored somewhere locally by the operating system. Just check this out, not sure how it's implemented in C++.

When the compiler compiles your C++ code, it generates native machine code right? Does the obj file only contain those instrutions?

There are three main types of object files.

1)A relocatable file holds code and data suitable for linking with other object files to create an executable or a shared object file.

2) An executable file holds a program suitable for execution; the file specifies how the execute call creates a program's process image.

3) A shared object file holds code and data suitable for linking in two contexts. First, the link editor processes the shared object file with other relocatable and shared object files to create another object file. Second, the dynamic linker combines it with an executable file and other shared objects to create a process image.

I hope that came close to answering your question, I'm not sure whether this is what you were looking for, so ask again if it was not.

I sometimes think that to be a true great when it comes to C/C++, one has to have some compiler design experience, then only you can truly know all the small nuances associated with this language.

dinesh.

Re: Coder to Developer

They've already started to somewhat monopolize the search market.

There are two types of monopolies, Coercive and Non-Coercive Monopolies. Google is a non-coercive monopoly, so let them enjoy it. They certainly deserve it. In a non-coercive monopoly, people always have the choice not to make use of a service. No one's "forcing" people to use google, it just got that way because they are good.

dinesh.

RSS

RSS is an acronym for a a couple of terms (dunno which one's official)... "Rich Site Summary" and "Really Simple Syndication". This is an xml standard for content aggregation. The idea is simple. Instead of going to different sites to see what new content is available, you get notified of what's new. This is made possible with the agreed upon format which is RSS. The idea has been there for a while with both Netscape and Microsoft coming up with their own formats, but it didn't take off until the RSS standard came about.

RSS can be used for any sort of content. Probably the most popular use of RSS will be from news sites as that content is ALWAYS being updated. But it is used for all sorts of stuff including comics and blogs. There is a rival format called "Atom" and Google has gotten behind that, so the Blogger feeds are in the "Atom" format. Infact codeword has a blog feed... http://codeword.blogspot.com/atom.xml.

You would need some sort of feed aggregator application to make use of the feeds. You give the app URL's to the site feeds (like the codeword feed). If you look at news sites like BBC or Slashdot, they will have a red graphic with the word "XML" on it. That's the feed URL for the site. As the content on the site is updated, the RSS document is updated. The feed aggregator app periodically checks this document and informs you that the content has been updated. So as an example, instead of visiting http://codeword.blogspot.com everyday to check if something new has been posted, the feed aggregator app will tell you. I use Abilon. It's very basic and does everything an aggregator would need to do.

It's such a simple concept. The only thing that was needed was a standard and now with RSS/Atom they have it. I really feel like it's a "killer app".

Sunday, May 23, 2004

Stack

I thought I had a clear idea about the Stack memory, but something popped in my head and now I'm confused. So hopefully you can clarify this.

"The static storage area is simply a fixed patch of memory that is allocated before the program begins to run. Using the stack or static storage area places a priority on the speed of storage allocation and release, which can be valuable in some situations."

What does "allocated before the program is run" mean exactly? Does it just mean that the OS "reserves" some area of memory and uses that as a stack (keep pushing on the function calls etc... in this area) in a FILO manner? Whereas the heap is just another chunk but you are free to allocate anywhere.

When the compiler compiles your C++ code, it generates native machine code right? Does the obj file only contain those instrutions?

Re: Coder to Developer

What the hell happened to the blogs interface, I do not like this new one.

They upgraded the entire system recenty. Check out The Great Blogger Relaunch

What impression dyou have of Google? They're everywhere nowdays and keeps getting billed as the the hottest company on earth (at the moment). Everything they do is something unique and different - either in coming up with something new or improving on stuff thats already out there. They also have the "DO NO EVIL" policy which they publicized when they announced they were going public.

But how long dyou think this will last? I feel the more successful they get they'll acquire a more of a Microsoft image. They've already started to somewhat monopolize the search market. The market share won't statistically prove that, but c'mmon "to google" has become a verb in common lingo. With everyone relying on google for their information/search needs, the search engine market is fast resembling the OS market. It's also becoming a situation where people start thing, if you can't find it with Google, you can't find it anywhere else. They're even planning on "Puffin" - a search product for your local machine.

Also, as they head towards becoming a public company, they're driving force will be to generate more income/profits to satiate their share holders. They're ads will get more prominent. They've been very smart about it and have clearly been mindful of it until now, with not making it intrusive. But I read somewhere recently they were experimenting with graphic ads. It will be interesting to see where they are and how they are perceived in another 5 years. What dyou feel?

Just want to make clear that I really like google and all the services they provide. They definitely do have the best search out there - personally I have the most success with them. Also the GMail interface is fantastic - probably the most innovation that's occured in that area in a LONG time. But I just feel like this "darling" image everyone has of Google (including themselves) cannot last forever.

Tuesday, May 18, 2004

Effect of Indian Elections

just check this link out Indian Outsourcing

dinesh.

Monday, May 10, 2004

Re: Coder to Developer

I just feel like once we have been exposed to this stuff, we are left on a ledge somewhere to our own devices. Without knowing why or where they could be applicable. Some stuff I'm learning in Automata Theory seems quite interesting. It's just a very frustrating learning experience because I have no idea when, where or why I would use it. And that just makes you dislike the subject. This has been my experience in all such classes. It's not a one off deal.

Damn well put. I know exactly what you mean, some things are just not fathomable unless you see how it applies in reality. I think Tanenbaum in his operating systems book, makes a statement that " ... some of it is of no use, other than maybe keeping a few graph theorists employed" :). I remember laughing so much when i read that, i don't remember precisely what he was talking about, but in the context it was really funny. Sometimes, I almost come to believe it's true. I'm sure I will come across this in the future too, when i do more in AI, though personally,i want to be a master at both theory and practice :):)

dinesh.

p.s. - What the hell happened to the blogs interface, I do not like this new one.

Sunday, May 09, 2004

Re: Coder to Developer

Thing is that there is nothing inherently bad with "theoritical stuff". The reason it works in practice is because it is sound in theory in the first place.

I completely agree with you. I feel like with my tirades on theoretical stuff, I've given a wrong impression that I think they are totally useless. They are not. On the contracty. They are VERY important.

It's just that colleges tend to stop at theory without showing you how it applies or how we are supposed to apply it in physical reality.

Another excellent point. I just feel like once we have been exposed to this stuff, we are left on a ledge somewhere to our own devices. Without knowing why or where they could be applicable. Some stuff I'm learning in Automata Theory seems quite interesting. It's just a very frustrating learning experience because I have no idea when, where or why I would use it. And that just makes you dislike the subject. This has been my experience in all such classes. It's not a one off deal.

I realize this stuff is important since it forms the basis of CS. But at the same time, I also see that most people pursuing a CS degree are in it cause of the practical stuff. They want to learn stuff they will use in the real world. It's like the 80/20 rule. Focus on practical classes like software design, testing, good coding practices etc... that 80% will find useful and leave the heavy scientific stuff to the 20% who do want to work on the mathematical/research stuff.

Re: Coder to Developer

Thing is that there is nothing inherently bad with "theoritical stuff". The reason it works in practice is because it is sound in theory in the first place. It's just that colleges tend to stop at theory without showing you how it applies or how we are supposed to apply it in physical reality. Go through any college course and most of it is about mathematical formalism (things like your NP completeness or in physics - strings theory), rather than basing views on reality. That is what i think is wrong with most college courses.

dinesh.

Thursday, May 06, 2004

Re: Coder to Developer

"The more you know, the less you feel you know".

I read this quote somewhere (dunno if that's the exact quote), but I feel it applies pretty well to the topic. It's about relativity. The more you know, the more you read, the broader picture you get of what's out there. It's only then dyou realize how little you actually know comparatively.

Looking at job requirements and seeing the amount of stuff a potential candidate needs to know is a pretty huge humbling experience. I agree with everything he said about colleges not teaching the "good" practical stuff. It's almost as if he read my mind about that subject. It goes back to a discussion we had a while back about "theoretical crap" (my term) vs real world stuff.

Coder to Developer

There's a new book out called "Coder to Developer". The reviews have been overwhelming good. Anyway, the guy who wrote the foreword, posted it on his blog...

-----------------------------------------
You know what drives me crazy?

“Everything?” you ask. Well, OK, some of you know me a bit too well by now.

But seriously, folks, what drives me crazy is that most software developers don’t realize just how little they know about software development.

Take, for example, me.

When I was a teenager, as soon as I finished reading Peter Norton’s famous guide to programming the IBM-PC in Assembler, I was convinced that I knew everything there was to know about software development in general. Heck, I was ready to start a software company to make a word processor, you see, and it was going to be really good. My imaginary software company was going to have coffee breaks with free donuts every hour. A lot of my daydreams in those days involved donuts.

When I got out of the army, I headed off to college and got a degree in Computer Science. Now I really knew everything. I knew more than everything, because I had learned a bunch of computer-scientific junk about linear algebra and NP completeness and frigging lambda calculus which was obviously useless, so I thought they must have run out of useful things to teach us and were scraping the bottom of the barrel.

Nope. At my first job I noticed how many things there are that many Computer Science departments are too snooty to actually teach you. Things like software teamwork. Practical advice about user interface design. Professional tools like source code control, bug tracking databases, debuggers and profilers. Business things. Computer Science departments in the most prestigious institutions just won’t teach you this stuff because they consider it “vocational,” not academic; the kind of thing that high school dropouts learn at the local technical institute so they can have a career as an auto mechanic, or an air-conditioner repairman, or a (holding nose between thumb and forefinger) “software developer.”

I can sort of understand that attitude. After all, many prestigious undergraduate institutions see their goal as preparing you for life, not teaching you a career, least of all a career in a field that changes so rapidly any technologies you learn now will be obsolete in a decade.

Over the next decade I proceeded to learn an incredible amount about software development and all the things it takes to produce software. I worked at Microsoft on the Excel team, at Viacom on the web team, and at Juno on their email client. And, you know what? At every point in the learning cycle, I was completely convinced that I knew everything there was to know about software development.

“Maybe you’re just an arrogant sod?” you ask, possibly using an even spicier word than “sod.” I beg your pardon: this is my foreword; if you want to be rude write your own damn foreword, tear mine out of the book, and put yours in instead.

There’s something weird about software development, some mystical quality, that makes all kinds of people think they know how to do it. I’ve worked at dotcom-type companies full of liberal arts majors with no software experience or training who nevertheless were convinced that they knew how to manage software teams and design user interfaces. This is weird, because nobody thinks they know how to remove a burst appendix, or rebuild a car engine, unless they actually know how to do it, but for some reason there are all these people floating around who think they know everything there is to know about software development.

Anyway, the responsibility is going to fall on your shoulders. You’re probably going to have to learn how to do software development on your own. If you’re really lucky, you’ve had some experience working directly with top notch software developers who can teach you this stuff, but most people don’t have that opportunity. So I’m glad to see that Mike Gunderloy has taken upon himself to write the book you hold in your hands. Here you will find a well-written and enjoyable introduction to many of the most important things that you’re going to need to know as you move from being a person who can write code to being a person who can develop software. Do those sound like the same thing? They’re not. That’s roughly the equivalent of going from being a six year old who can crayon some simple words, backwards N’s and all, to being a successful novelist who writes books that receive rave reviews and sell millions of copies. Being a software developer means you can take a concept, build a team, set up state of the art development processes, design a software product, the right software product, and produce it. Not just any software product: a high quality software product that solves a problem and delights your users. With documentation. A web page. A setup program. Test cases. Norwegian versions. BokmÃ¥l and Nynorsk. Appetizers, dessert, and twenty seven eight-by-ten color glossy photographs with circles and arrows and a paragraph on the back of each one explaining what each one was. (Apologies to Arlo Guthrie.)

And then, one day, finally, perhaps when it’s too late, you’ll wake up and say, “Hmm. Maybe I really don’t know what it really takes to develop software.” And on that day only, and not one minute before, but on that day and from that day forward, you will have earned the right to call yourself a software developer. In the meantime, all is not lost: you still have my blessing if you want to eat donuts every hour.
----------------------------------------------------------------------