Is STL important?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 31

Thread: Is STL important?

  1. #1
    Join Date
    Sep 2009
    Posts
    2

    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.

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,891

    Re: Is STL important?

    You can make do without it, but it'll make your life much easier in the long run.

  3. #3
    Join Date
    Jun 2006
    Posts
    437

    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.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,444

    Re: Is STL important?

    Quote Originally Posted by norsul View Post
    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

  5. #5
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    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.

  6. #6
    Join Date
    Oct 2005
    Location
    England
    Posts
    803

    Re: Is STL important?

    Quote Originally Posted by norsul View Post
    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

  7. #7
    Join Date
    May 2009
    Posts
    2,413

    Re: Is STL important?

    Quote Originally Posted by norsul View Post
    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.

  8. #8
    Join Date
    Sep 2009
    Posts
    2

    Re: Is STL important?

    Ok thanks guys, I'll read the chapter

  9. #9
    Join Date
    Dec 2007
    Location
    Lithuania
    Posts
    98

    Re: Is STL important?

    Quote Originally Posted by norsul View Post
    Ok thanks guys, I'll read the chapter
    Don't read it. Understand it
    Share and always try to give back more.

  10. #10
    Join Date
    Jan 2006
    Location
    Belo Horizonte, Brazil
    Posts
    405

    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.

  11. #11
    Join Date
    May 2009
    Posts
    2,413

    Re: Is STL important?

    Quote Originally Posted by ltcmelo View Post
    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 10:27 PM.

  12. #12
    Join Date
    Jan 2006
    Location
    Belo Horizonte, Brazil
    Posts
    405

    Re: Is STL important?

    Quote Originally Posted by nuzzle View Post
    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...

    Quote Originally Posted by nuzzle View Post
    In principle generics is just another a form of polymorphism. 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.
    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.

    Quote Originally Posted by nuzzle View Post
    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.

  13. #13
    Join Date
    May 2009
    Posts
    2,413

    Re: Is STL important?

    Quote Originally Posted by ltcmelo View Post
    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.

  14. #14
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,725

    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

  15. #15
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,725

    Re: Is STL important?

    Quote Originally Posted by Paul McKenzie View Post
    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

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center