CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: getting string size at run time

    Quote Originally Posted by aijazbaig1
    My objective is to get a fair grasp over C before plunging into C++.
    It's generally considered better to plunge straight into C++ if that is your end objective, otherwise you will learn a whole lot of C idioms that would be considered either unnecessary or bad practice under C++.

    I know from experience of working with C for 10 years before moving to C++. My early programs are a horrible mish-mash of C and C++ styles as I slowly got to understand C++ and object orientated programming.

  2. #17
    Join Date
    Apr 1999
    Posts
    27,449

    Re: getting string size at run time

    Quote Originally Posted by aijazbaig1
    My objective isto get a fair grasp over C before plunging into C++.
    Why do you think you need to learn 'C' before learning C++?

    http://www.parashift.com/c++-faq-lit....html#faq-28.2

    Regards,

    Paul McKenzie

  3. #18
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Re: getting string size at run time

    Quote Originally Posted by aijazbaig1
    Is there an even more efficient way in which we can allocate memory for each single character each time before reading a character at that location?
    Of course you can achieve that. You can write a linked list of characters. And you will get what you want. But allocating a smaller chunk and then doubling the size each time you exceed the limit would be better.

    Jump to C++ though, there are many more things to learn that to keep wondering about character arrays and how to deal with them. Quicker programming is the need of the hour and the world is moving fast in terms of development technologies unless C-styles strings are part of your curriculum.

  4. #19
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    19

    Lightbulb Re: getting string size at run time

    Hello.
    Thanks a lot for so many wonderful comments that I received. Well this has put me into some kinda dilemma if I should abandon what I am presently doing with C?
    Well, another reason why Im learning C is that I would be taking a course later in the fall semester on Operating systems concepts and a lot of code is still written in C and some in Java( as the book says that multithreading cannot be easily implemented using C ).
    So heres the deal, my main intention is to be able to acquire enough skills to create windows based applications using VC++ but I still dont wanna go down on the implementation part in that course which I mentioned above..

    Dont know where to head now..can I start with VC++ afresh..I have a book by gary bronson for VC++ exclusively but a whole bunch on C..is it possible to keep track of both if I ultimately decide to swim in both??..

    Guys help me here..life sure is a big roundabout...

    Best Regards,
    Aijaz Baig.

  5. #20
    Join Date
    Apr 1999
    Posts
    27,449

    Re: getting string size at run time

    Quote Originally Posted by aijazbaig1
    Hello.
    Thanks a lot for so many wonderful comments that I received. Well this has put me into some kinda dilemma if I should abandon what I am presently doing with C?
    There are many persons, such as myself and others here, who program both in 'C' and C++.

    The trick is to know when to use 'C' techniques and when to use C++ techniques. If the programmer is disciplined and studied C++ properly, he/she can code correct C++ and have no "bad" influences brought into the program from their C background.

    However, from my experience, there are still a lot of 'C' programmers who bring into a C++ program a lot of 'C' style coding, bringing about disastrous results (both in code maintenance and runtime bugs). These programmers are basically 'C' programmers who believed that since 'C' looks like C++, they can use the same techniques in a C++ program, and for the most part "winging it" (for those who are not familiar with the term "winging it", here it is from an online thesaurus):
    wing it
    To say or do something without preparation, forethought, or sufficient information or experience; improvise
    A quick look through some threads here have demonstrated this problem.
    Well, another reason why Im learning C is that I would be taking a course later in the fall semester on Operating systems concepts and a lot of code is still written in C and some in Java( as the book says that multithreading cannot be easily implemented using C ).
    Another wrinkle is Java. That is another issue that has been discussed here a lot, and the big issue is Java programmers trying C++ and "winging it" on the C++ side. The C++ programs written by these particular Java programmers are just as, if not more, disastrous than 'C' programmers who "wing it" with their C++ programs.
    So heres the deal, my main intention is to be able to acquire enough skills to create windows based applications using VC++
    Well, you need to learn the C++ part of VC++ first.
    Dont know where to head now..can I start with VC++ afresh..I have a book by gary bronson for VC++ exclusively but a whole bunch on C..is it possible to keep track of both if I ultimately decide to swim in both??..
    Hard to say. However, when you're coding in C++, always think in terms of C++ first, and a 'C' based solution second. In other words, use vector, std::string, etc. instead of coding these yourself, etc.

    I would get Accelerated C++ by Koenig & Moo. This introduces C++ to the programmer who already knows 'C' or some other language, and gets them on the right track.

    Regards,

    Paul McKenzie

  6. #21
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: getting string size at run time

    Quote Originally Posted by JohnW@Wessex
    It's generally considered better to plunge straight into C++ if that is your end objective, otherwise you will learn a whole lot of C idioms that would be considered either unnecessary or bad practice under C++.
    Yes, but I think that it is mainly due to programmer's lazyness... And the lack of understanding that C and C++ are two different languages...
    I mean that C doesn't "pollute the mind" like many guys say for BASIC.
    No... C doesn't pollute the mind.

    aijazbaig1 : If you are aware of that issue you can learn C or C++ first... It should not matter that much.
    But don't forget that you must not blindly apply what you have learnt in C in C++ ... You must try to find a better (more C++-ish) way to do things. It is an active learning process.

    After all... I started with ugly GOTO-ish BASIC... Writing spaghetti code. But I don't program in C++ like I did in BASIC.
    Similarly, at the start of my learning curve of C++, most information I got about C++ was on the C-with-classes subset of C++.

    And also, don't forget that sometimes (not for everybody) very high-level concepts such as OOP are impossible to learn without understanding why they are useful... And sometimes you can only understand why you need them if you learnt to program with an object-based language (or subset of language)... And the object-based system can be well understood if you learn procedural programming...

    Don't forget that OO features are a superset of object-based features which are a superset of procedural features.

    I said that, because I have seen a lot of Java programmers programming with a much worst style than I could ever think of... They didn't even understood procedural concepts.

    That's probably because, OO concepts are the not intuitive (at least for most people)... And if you think that they're really intuitive and easily applicable... You are either a genious or don't get them at all. With a bad understanding of OO, you'll get more productive, and produce more extensible code in a functional language... or even a procedural language.

    Well, another reason why Im learning C is that I would be taking a course later in the fall semester on Operating systems concepts and a lot of code is still written in C and some in Java( as the book says that multithreading cannot be easily implemented using C ).
    Well, in my experience, C and C++ are the best languages for multithreading (even if it is quite difficult to write in a thread-safe way)... They have no builtin support for multithreading but they can use all the various synchronisation objects & multithreading objects which exists in the world... Java has a very simple but limited concept of thread synchronisation which is good for beginners but far less powerful than C and C++.
    And, of course, if you want to understand how the OS works, Java is very bad at that.
    C and assembly language are the best for that (Linux is programmed in C).
    "inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
    Club of lovers of the C++ typecasts cute syntax: Only recorded member.

    Out of memory happens! Handle it properly!
    Say no to g_new()!

  7. #22
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Re: getting string size at run time

    Quote Originally Posted by Paul McKenzie
    However, from my experience, there are still a lot of 'C' programmers who bring into a C++ program a lot of 'C' style coding, bringing about disastrous results (both in code maintenance and runtime bugs). These programmers are basically 'C' programmers who believed that since 'C' looks like C++, they can use the same techniques in a C++ program, and for the most part "winging it"
    It was the story with me as well when I knew only C and was to code in C++. I started rightaway with the project coding in C style. Thank God, that things went fine even then and I did not mess it up - however when I think back, I can just imagine how much value I could have had added to the project had I been aware of C++ and used it well.

    C to C++ is a big move and the basic ideology is different. To figure out and understand the essence of OOP is tough when you take this move but once you get to know it better in "your own words" and not "bookish terms", there is a big difference.

  8. #23
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    Re: getting string size at run time

    Java has a standard library for threads but part of the problem is that there is no RAII in Java except for memory, so any thread resource like a mutex must be explicitly released after it is acquired. Of course they do have the "finally..." block to cope with it but it still puts the burden on the programmer. (Garbage collection doesn't work with resources like mutexes).

    I have seen some Java code and actually I find a lot of it is overly procedural too. They have switch..case in Java and it is often overused, as are abundant numbers of 'if' statements where interfaces and polymorphism could be used instead. Changing language doesn't make a bad programmer into a good one.

    It can be useful to know C as a language, partly because there are projects done in C, particularly in the embedded world, and also partly because a lot of the work you would be doing as a C++ programmer would involve supporting, maintaining and modifying other people's code as well as writing your own, and you would need to know C for that. In addition, if you write a C++ library it is quite likely you might want to give it a "C" interface and you would need to know what that means.

    (My opinion on that matter is that you should give it both a C and a C++ interface and that the library should preferably be written in C++).

  9. #24
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: getting string size at run time

    Quote Originally Posted by Paul McKenzie
    These programmers are basically 'C' programmers who believed that since 'C' looks like C++, they can use the same techniques in a C++ program, and for the most part "winging it"
    For me it wasn't a deliberate decision to "wing it". At the time, I had put forward the idea to use C++ for the next project as it appeared to have, as standard, many of the things I had been coding the 'hard way' in C (and assembler). Unfortunately I was tasked to write the new code whilst trying to learn C++. This meant that my code started with a rather high C to C++ ratio. By the time I got sent on a training course, a substantial amount of code had been written. Eventually you are made to pay for this lack of training when you are tasked to maintain your old code .

Page 2 of 2 FirstFirst 12

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured