Bad Advices

Pages: 12345
closed account (N36fSL3A)
But C is part of C++, so that WOULD make it C++, right?

Vectors deep down use dumb pointers, so ultimately they'd be part of C.
Vectors deep down use dumb pointers, so ultimately they'd be part of C.


Um... no.

C++ and C are different languages. C++ attempts to be "backwards compatible" with C, but it isn't completely. There are enough differences between the two to say that they are clearly, and without question, two independent and distinctly different languages.

There is C++ code that will not compile in C, and vice versa. There is C code that will compile in C++, but will do something different in C++ than it would in C.



So really this whole "if it uses raw pointers it's C / if it uses OOP it's C++" nonsense is... well... nonsense. If it's C code, it's C. If it's C++ code, it's C++.
Vectors deep down use dumb pointers, so ultimately they'd be part of C.


I would give you the same advice I gave to BHXSpecter. Use common sense.

Can you use a vector in C? No? What does that tell you?
closed account (3qX21hU5)
Well technically deep down C++ is just Electrons so I guess we are programming in Electrons :)

I really don't get how people don't get when you are using C++ you are using C++...
Last edited on
cire wrote:
I would give you the same advice I gave to BHXSpecter. Use common sense.

I've been asking around and looking into it more. The more I talk to others and the more tutorials I look at, the more I see why even with common sense people say learning C++ is just learning C until you learn classes and OOP. For example, here is the C and C++ tutorials from Cprogramming.com http://prntscr.com/1sg6i3 <= best example as to why I can see why they say learning C++ is like learning C. It is just a misconception that seems logical even with common sense due to how tutorials make them both look when compared side by side.
TBH I didn't read everything but the reason people use vectors is because they are easy to use and work for almost everything.

http://i.stack.imgur.com/kQnCS.png
> The more I talk to others and the more tutorials I look at, the more I see why
> even with common sense people say learning C++ is just learning C until you learn classes and OOP.

Perhaps you should consider talking to people who know the rudiments of C++. And look at tutorials that are of marginally better quality than the ones that you have perused so far. For instance, a tutorial where where the second program after the obligatory "Hello World!" may be something like:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <string>

int main()
{
     std::cout << "please type in your first name: " ;
     std::string name ;
     std::cin >> name ;
     std::cout << "Hello " << name << '\n' ;
}
closed account (S6k9GNh0)
That would be a bad tutorial. The beginner might try using std::cin a second time in that manner and get caught in a pitfall.
@JLBorges
Well that would be considered bad advice. If you jump from the "Hello World!" tutorial straight to input that means you skip over teaching variables and data types. Look at the tutorials on this site:

*Basics of C++*
**Structure of a program
**Variables. Data types.
**Constants
**Operators
**Basic Input/Output


Also I was just pointing out, on the surface I can see why so many say or think learning the basics of C++ is just learning C until you get to classes and OOP.
> That would be a bad tutorial. The beginner might try using std::cin a second time in that manner and get caught in a pitfall.


What pitfall? By the way, that was a program, which could have been part of a C++ tutorial; it is not the tutorial in its entirety.

Though, I can see why to a C fanboy, this would be a really terrible second program to appear in a tutorial. The program example (with equivalent functionality), in a really good C++ tutorial ought to have been (adapted from 'Learning Standard C++ as a New Language' - Stroustrup):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
    size_t sz = 20 ;
    char* name = (char*)malloc(20) ;
    if( name == NULL ) return 1 ;

    puts( "please type in your first name: " ) ;

    int c ;
    while( ( c = getchar() ) != EOF )
    {
        if( !isspace(c) )
        {
            ungetc( c, stdin ) ;
            break ;
        }
    }

    size_t pos = 0 ;
    while( ( c = getchar() ) != EOF )
    {
        if( isspace(c) )
        {
            name[pos] = 0 ;
            break ;
        }

        name[pos] = c ;
        if( pos == sz-1 )
        {
            sz *= 2 ;
            char* temp = (char*)realloc( name, sz ) ;
            if( temp == NULL )
            {
               free(name) ;
               return 1 ;
            }
            else name = temp ;
        }
        ++pos ;
    }

    printf( "Hello %s\n", name ) ;
    free(name) ;
}




> Well that would be considered bad advice. If you jump from the "Hello World!" tutorial straight to input ...

What? You have started with the "Hello World!" program?
Without first teaching:

*Basics required for Hello World*
**Structure of a program
**Functions ( int main(), for heavens sake!)
**Scopes ( what is this { ... }? )
**Variables. Data types. (std::cout is a variable, and it has a type)
**Constants (yes, very important before we can talk about string literals)
**Operators, including overloaded operators ( << )
**Basic Input/Output (No, just output would suffice for Hello World!)
**The C preprocessor and (Yes, or else we can't have #include <iostream>, can we?)
**The separate compilation model and linkage (how does this std::cout manifest itself?)
** namespaces (std::)


Once you have taught all that before the first "Hello World" example, my teaching how to read and write a string for the second example is a piece of cake.
Last edited on
Seems a bit much for that simple program lol
It is a bad tutorial that jumps straight to cin >> a_string. Unless the larger tutorial were using it as an example of how to shoot your foot.

Input is notoriously difficult, and one of the biggest pitfalls in C and C++ is that everyone seems to think it is simple.

Every time you ask the user for something, it is safe to expect the user to press the Enter key. Get strings with std::getline().
Okay, C++ was the first language I ever learned on my own. I did BASIC in 7th and 8th grade, but never really remembered any of that after 8th grade. I'm not a fanboy of any language and even I would never make the second tutorial example a program that did input before ever even touching data types, variables, and then go to input and output.
> t is a bad tutorial that jumps straight to cin >> a_string.
> ... Get strings with std::getline().

If that is bad, this would be terrible:
1
2
3
4
5
6
std::cout << "please type in your first name: " ;
std::string name ;
std::getline( std::cin, name ) ;
// use an istringstream to parse the input and extract the first name
// where one would do stm >> a_string ; any way.
// Unless the intent was to parse it character by character 


std::cin >> name ; is the simplest, and the correct way to read in a white space delimited sequence of characters.
Just as std::getline( std::cin, name ) ; is the simplest, and the correct way to read in an entire line which may contain white spaces.
Last edited on
to pick up an earlier branch of this thread,
LB wrote:
you can basically plug-and-play with any of the popular standard library implementations

Incidentally, i can't agree with that: C++ standard libraries are tightly integrated with their respective compilers: core language features rely on the standard library (e.g. they throw exceptions and call functions defined in std::), and standard library implementations require intimate knowledge of the non-portable compiler intrinsics and implementation details of all supported compilers, as well as the low-level APIs of all supported operating systems and, to some extent, CPUs. Providing standard, portable API to all that is of the reasons the library exists.

There are a couple cases where two compilers can use the same library or one library can be used with two compilers, but they took a lot of work.
Last edited on
Took me all of an hour to rummage through my book collection, to locate the introductory text teaching C++ which had the program I posted earlier (The C++ program, not the C program masquerading as a C++ program) as the second example after the first "Hello World!" example.

From Chapter 1 of 'Accelerated C++: Practical Programming by Example' by Koenig and Moo:

1. Working with strings
Chapter 0 looked at a small program, which we used to introduce surprisingly many fundamental C++ ideas: comments, standard headers, scopes, namespaces, expressions, statements, string literals and output. This chapter continues our overview ...

1.1 Input
Once we can write text, the next logical step is to read it. For example, we can modify the "Hello world!" program to say hello to a specific person:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// ask for a person's name and greet the person
#include <iostream>
#include <string>

int main()
{
     // ask for the person's name
     std::cout << "Please enter your first name: ";
     
     // read the name
     std::string name;    // define name
     std::cin >> name;    // read into
     
     // write a greeting 
     std::cout << "Hello, " << name << "!" << std::endl;
}


When we execute this program, it will write

Please enter your first name:

on the standard output. If we respond, for example,

Vladimir

then the program will write

Hello, Vladimir

Let us look at what is going on. In order to read input, we must have a place to put it. Such a place is called a variable. A variable is an object that has a name. An object ...
But the question is, JLBorges... is Vladimir from Moscow?
Vladimir from Moscow is still missing.

After he was off for a few days, I looked at the profile and it said: 'This account has limited functionality. This was likely due to the user being reported etc..'. Looked at it now, and it remains the same.

I wonder when his account will be put back to normal. Would it help if I send a mail to the admin to remind him that it is about two weeks now? Take away the frequent invectives, and he would be an asset to the forum.
closed account (z05DSL3A)
Would it help if I send a mail to the admin to remind him that it is about two weeks now?

I sure that Vlad is capable of talking to the admin himself if he wants to come back (as Vlad from Moscow).
Choosing the worst possible way to do something does not make a valid counter-argument.
Pages: 12345