-
September 18th, 2009, 10:36 AM
#1
Is STL important?
I'm just starting programming and I've made it until the Standart Template Library. But the chapter seems incredibly boring, daunting and complicated, it looks so awful that I haven't yet read it so I can't really say is it complicated or not. So is it a very important thing or can I just skip it and live happily? I'm just kinda lazy to read the 30 pages dedicated to STL.
-
September 18th, 2009, 10:43 AM
#2
Re: Is STL important?
You can make do without it, but it'll make your life much easier in the long run.
-
September 18th, 2009, 10:52 AM
#3
Re: Is STL important?
Hi all.
Only 30 pages????
It's a little introduction to the topic!!!!!
Well, I've developed in C++ for long time, and I used STL very rarely. But I think that it's a very important argument, and we can see STL as a part of C++ programming. If you know STL you can use a powerful programming tool to build your application (without re-invent the wheel, as we say).
Moreover one good reason to study accurately STL is that it's a standard, and you'll find it on every serious programming environment you are going to use, Visual C++ for Microsoft as well as aCC for Unix.
-
September 18th, 2009, 11:06 AM
#4
Re: Is STL important?
Originally Posted by norsul
I'm just starting programming and I've made it until the Standart Template Library. But the chapter seems incredibly boring, daunting and complicated, it looks so awful that I haven't yet read it so I can't really say is it complicated or not. So is it a very important thing or can I just skip it and live happily? I'm just kinda lazy to read the 30 pages dedicated to STL.
Without STL, write a program that creates an array of "n" integers. The "n" is inputted by the user. Once you do that, write a function to insert and remove items from this array. After that, write a program that sorts the integers in descending order. Make sure that all memory allocation and deallocation is done properly.
After you code this, you will see why STL is a powerful library. The code you will need to accomplish the above without STL is by far, much harder to write and maintain than with STL.
Regards,
Paul McKenzie
-
September 18th, 2009, 11:08 AM
#5
Re: Is STL important?
The STL for C++ programmes is as important as a car, ship or airplane. You can get everywhere without these vehicles, but it will take you days, months or probably years.
- Guido
-
September 18th, 2009, 11:40 AM
#6
Re: Is STL important?
Originally Posted by norsul
I'm just starting programming and I've made it until the Standart Template Library. But the chapter seems incredibly boring, daunting and complicated, it looks so awful that I haven't yet read it so I can't really say is it complicated or not. So is it a very important thing or can I just skip it and live happily? I'm just kinda lazy to read the 30 pages dedicated to STL.
I would recommend reading the introduction so you are familiar with what can be achieved with the STL. Then begin to learn specific parts as you come across problems that can be solved using components of the STL.
Rich
Visual Studio 2010 Professional | Windows 7 (x64)
Ubuntu
-
September 18th, 2009, 04:19 PM
#7
Re: Is STL important?
Originally Posted by norsul
So is it a very important thing or can I just skip it and live happily?
It's an essential part of C++. For one thing because a large part of the C++ standard library uses it but also because it represents a special programming paradigm called generics which is as important as object oriented programming, if not more so.
-
September 19th, 2009, 01:33 AM
#8
Re: Is STL important?
Ok thanks guys, I'll read the chapter
-
September 19th, 2009, 06:35 AM
#9
Re: Is STL important?
Originally Posted by norsul
Ok thanks guys, I'll read the chapter
Don't read it. Understand it
Share and always try to give back more.
-
September 19th, 2009, 07:39 AM
#10
Re: Is STL important?
In my opinion there are two major benefits you can get from a good understanding of the STL.
1 - The most obvious one is that you improve your C++ abilities. You can do pretty amazing things combining all STL capabilities like containers, algorithms, iterators and function objects. Most fundamental algorithms and data structures are there.
2 - You can learn from its design. In particular, you get a feel on the power of generic programming, which is the development paradigm of the STL. (If you don't know yet, the STL is not constructed on a traditional object oriented paradigm.) You'll have a great example of how to build reusable and extensible software libraries.
-
September 21st, 2009, 06:45 PM
#11
Re: Is STL important?
Originally Posted by ltcmelo
In my opinion there are two major benefits you can get from a good understanding of the STL.
1 - The most obvious one is that you improve your C++ abilities. You can do pretty amazing things combining all STL capabilities like containers, algorithms, iterators and function objects. Most fundamental algorithms and data structures are there.
2 - You can learn from its design. In particular, you get a feel on the power of generic programming, which is the development paradigm of the STL. (If you don't know yet, the STL is not constructed on a traditional object oriented paradigm.) You'll have a great example of how to build reusable and extensible software libraries.
There's also a point 3. This is when generics is used together with object orientation.
In principle generics is just another a form of polymorphism. For this see this defining paper,
http://lucacardelli.name/Papers/OnUnderstanding.A4.pdf
Here generics is called "parametric" polymorphism and the OO form of polymorphism is called "inclusion" polymorphism.
Fortunately in C++ we have both sorts, both parametric and inclusion polymorphism.
More unfortunate is that the implementor of generics in C++, Mr. Stephanov, is convinced generics is all that's needed. He bluntly rejects OO as total crap.
I don't agree with Mr. Stepanov. You sure can use generics and OO separately or in happy conjunction. It's not one or the other, it's both separately or together.
I've tried to understand Mr. Stepanovs position. I've even bought his book (there's just one) called Elements of Programming. And although his approach has its merits there's nothing in this book that explains how generics could replace OO. I've recently revieved his book at Amazon (as uj and I guess it will appear shortly).
Last edited by nuzzle; September 21st, 2009 at 09:27 PM.
-
September 21st, 2009, 10:41 PM
#12
Re: Is STL important?
Originally Posted by nuzzle
There's also a point 3. This is when you use
"generics lite" TOGETHER with object orientation.
I don't see that as point 3 the way you do. Basically, I consider this to be just a general ability. Still, keep reading...
Originally Posted by nuzzle
I have not read this paper yet. But I've seen different names for both kinds of polymorphism. So I get your point. Since we're in a C++ world, I think more appropriate names would be static polymorphism (GP) and dynamic polymorphism (OO). Those are the terms I've seen in books and references in general.
Originally Posted by nuzzle
Fortunately in C++ we have both sorts, both parametric and inclusion polymorphism.
More unfortunate is that the implementor of generics in C++, Mr. Stephanov, is convinced generics is all that's needed. He bluntly rejects OO as total crap. I don't agree with Mr. Stepanov. You sure can use generics and OO separately or in happy conjunction. It's not one or the other, it's both in happy conjunction.
I've tried to understand Mr. Stepanovs position. I've even bought his book (there's just one) called Elements of Programming. And although his approach has its merits there's nothing in this book that explains how generics could replace OO.
I haven't gotten his new book yet (but I sure will very soon). Anyways, without taking sides or claiming that this is Stepanov's argument, there is a subtleness on this issue that motivate different perspectives. Starting with...
What really is OO? What actually characterizes it? People have developed systems years before OO was widely accepted as a programming paradigm. Were they doing OO?
First, classes and objects. Maybe not with the same terms, but in the old C-style you had structs (you could even simulate member functions through function pointers). You can think of them being designed following a methodology concerned of identifying entities and their behaviour - the OO way. On the other hand, you can think of them being designed simply for the sake of satisfying the requirements of an algorithm or a family of algorithms - the GP way.
Next, encapsulation and abstraction. Are those really OO specific? I think people already wrote code with them in mind before OO. (I'm not even 30, but well... we're just exchaning thoughts, rigth?) Perhaps encapsulation and abstraction could be considered general guidelines of programming in many paradigms.
Inheritance and dynamic polymorphism are well known marks of OO. I think we can't argue on this one. However, in this case generic programming provides a nice alternative which is template style type binding and static polymorphism. More formally, concepts and models. (Which unfortunatelly are out of C++0x ) The point here is that both alternatives can be applied in most cases.
Perhaps, the biggest difference between the two paradigms is not language constructs or techniques. Instead it is a method of thinking. With OO you define classes/interfaces and then build algorithms on top of them. With GP, it's the other way around: You define algorithms and then you build concepts and data structures that can be submitted to them. While in OO the focus of the abstraction process is in creating entities, in GP the focus of the abstraction process is creating algorithms. With this in mind it's easier to understand how GP could replace OO and vice-versa.
-
September 21st, 2009, 11:30 PM
#13
Re: Is STL important?
Originally Posted by ltcmelo
I have not read this paper yet. But I've seen different names for both kinds of polymorphism. So I get your point. Since we're in a C++ world, I think more appropriate names would be static polymorphism (GP) and dynamic polymorphism (OO). Those are the terms I've seen in books and references in general.
That would be completely wrong. Static and dynamic polymorphism has nothing to do with what we're talking about here.
Here we're talking about polymorphisms of the type system of programming languages. Essentially there are 4 kinds - overloading, coercion, parametric and inclusion.
They were first defined in the paper I was referring to.
-
September 22nd, 2009, 03:10 AM
#14
Re: Is STL important?
The gospel according to JohnW@Wessex
1.0 Once upon a time there was a lowly programmer that wrote C++ in the C style of his forefathers.
1.1 One day, his employer said unto him, "Go forth to this advanced C++ course and return with knowledge of the mysteries of C++".
1.2 The wise sages at the course revealed many things that were previously unknown to him.
1.3 Upon his return he proclaimed, "The scales have been lifted from my eyes and now I see the wonders of the STL and generic programming".
1.4 His mind, now free from the confines of C Programming Paradigms, combined Object Orientated and Generic techniques to produce code that was simple, reusable and free from bugs.
1.5 And his employer was filled with joy that the productivity of his coder had dramatically improved.
May C++ neophytes learn from this humble C++ coder's journey.
There endeth the lesson.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
September 22nd, 2009, 04:18 AM
#15
Re: Is STL important?
Originally Posted by Paul McKenzie
Without STL, write a program that creates an array of "n" integers. The "n" is inputted by the user. Once you do that, write a function to insert and remove items from this array. After that, write a program that sorts the integers in descending order. Make sure that all memory allocation and deallocation is done properly.
I actually have written a set of interview questions that ask something like that. The aim is to see whether the interviewee uses the STL to solve the problem in a couple of lines or tries to implement the algorithm/container themselves. One question, that uses data indexed by strings, is virtually impossible to complete in the time provided without using std::map. Using std::map the task takes 11 lines of code, and that's including the curly brackets!
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|