Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

C++

Name: Anonymous 2008-09-17 13:47

1) Why do people not like C++?
2) Is C++ a good language to learn programming? Mind you, you don't need to use any of the advanced features.

Name: Anonymous 2008-09-17 13:56

Because it mixes high-level things like templates and STL, with low-level mechanisms like pointer arithmetic. This creates a complete chaos sure to confuse not only newbies, but every programmer.
It'd be hard to find a reasonably complete subset of C++ that allows showing simple concepts. Besides, there are languages simpler and much more fit for teaching beginners, like C (for low level concepts), Python, Scheme; even utter shit like Pascal is better for that.
Also, read C++ FQA.

Name: Anonymous 2008-09-17 13:59

>>2
2nded

Name: Anonymous 2008-09-17 14:05

Agree with >>2 , also optimizing a C++ program is a pain in the ass, and there are some issues with its OOP too - C++ is NOT an OO programming language, despite what people say. There are classes, templates, objects and shit like that but you can perfectly write a program without using them at all...shitsux. You should learn C, just that.

Name: Anonymous 2008-09-17 14:10

>>4
There's lots of whining about C++ not enforcing OO on everything, along with whining about Java enforcing OO on everything here.  So you'd rather have a Java approach?

Name: Anonymous 2008-09-17 14:14

1) FUCK
2) OFF

Name: Anonymous 2008-09-17 14:40

const * std::vector<const int* const> const v = new std:vector<const int* const>();
v.push_back(dynamic_cast<const int* const>(new int(5)));

Name: Anonymous 2008-09-17 14:44

NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL

Name: Anonymous 2008-09-17 15:37

>>7
moar liek
test.cpp: In function 'void print(const StringToStringMap&)':
test.cpp:8: error: conversion from
'std::_Rb_tree_const_iterator<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > > >' to non-scalar type
'std::_Rb_tree_iterator<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > > >' requested


amirite?

Anyway, what's ridiculous is how all these high-level features are just ugly hacks. Good luck trying to explain to a newbie why ++iterator in a for loop is faster than iterator++.

Name: Anonymous 2008-09-17 15:58

>>2
No, it's not because of that. It's because every feature it has integrates poorly with every other, sometimes even overlapping(!). Because the template system is a complete joke. It's Church-Touring equivalent, they say, but in the same way that Brainfuck is. Because for all the things it adds, it failed to add any to make your life easier. Even simple stuff, like keyword parameters. Sepples is literally a mind trap. Any person who tries to learn it well has just doomed themself to a life of fruitless labor and desperate evangelism on newsgroups.

Name: Anonymous 2008-09-17 16:16

And what does /prog/ think of D? I think they did a good job extracting from C++ and Java something that actually doesn't suck as much.
Anyone had any experience with this language?

Name: Anonymous 2008-09-17 17:13

Thanks for that.
I asked because I argued with someone why a newbie should not use C++ to learn programming and instead use something easier. Basically what >>2 said.

>>11
Sadly, no. But I would like to know, too.

Name: Anonymous 2008-09-17 17:56

Even if a language is bad, you can still learn programming in it.

Name: Anonymous 2008-09-17 18:03

>>13
I wrote Tetris using only MediaWiki templates. It was up for about an hour before a bot came, reverted my edits and banned my entire IP range indefinitely. It was then that I vowed to destroy the blasted Abelson-loving establishment with my parenthesis.

Name: Anonymous 2008-09-17 18:21

>>11
I've been following the specs a bit, though I haven't had the opportunity to use it for anything big yet. It looks like 2.0 is growing into a monster.
It's still more of a cleanly and strong monster, not a slime-dripping and lanky one with teeth everywhere but its mouth and largely unconnected body parts that look like they might fall off at any moment, like C++ is.
Still, I'm glad I don't have to implement the thing. I may try to get it working on an ARM platform soon, but I hope gcc will do all the magic bits and just work.

Name: Anonymous 2008-09-17 19:07

>>13
Just because you can do something, it doesn't mean you should.

Name: Anonymous 2008-09-23 16:36

I love how people bash C++ just by showing examples of the STL. You have to realize that you don't have to use the Shitty Template Library.

Name: Anonymous 2008-09-23 16:51

>>17
LOL i getit hahaha s/standard/shitty I GET IT LOLOLOL
XD a grat big one XD

Name: Anonymous 2008-09-23 17:30

>>17
You have to realize that the alternative is no generics at all.

Name: Anonymous 2008-09-23 18:02

>>17
STL is the best fucking thing ever to happen to C++.  Don't blame the language just because you're too stupid to use it.

Name: Anonymous 2008-09-23 19:01

C++ isn't that bad when you pick a reasonable set of features and use those. You shouldn't be mixing C and C++ style programming.

Name: Anonymous 2008-09-23 19:36

>>20
Hey now, don't be like that. It may be the best thing to happen to Sepples, and better than nothing, but that doesn't make it any good.

Name: Anonymous 2008-09-23 19:43

>>20
You, sir, confuse tolerance for convoluted design (and poor documentation) with intelligence.

Name: Anonymous 2008-09-23 19:54

wat

Name: Anonymous 2008-09-23 19:54

>>21
Well, yeah, but the problem is that most of the C++ features are terrible and likely to fuck you over.

Stroustrup should have kept it as "C with classes", and that should have been it.

Name: Anonymous 2008-09-23 20:11

>>25
There is always Objective-C.

Name: Anonymous 2008-09-23 20:31

>>26
Indeed, that's much better than C++. I wish that would have become the "industry standard" so that business idiots would have got obsessed with that thing instead of C++. The world would have been a happier place. Who knows, maybe Sun wouldn't have tried to fix it achieving an even greater failure of colossally epic proportions.

Name: Anonymous 2008-09-23 20:34

>>27
G-G-Get a Mac!

Name: Anonymous 2008-09-23 20:35

>>28
F-F-Fag! I'm not one! I was talking about real computing!

Name: Ultimate Desu Machine 9000 !!4tCZGW1yibnzNNd 2008-09-23 20:36

0000111111111111000000000111111111111111111000000000001111111111000000000011111100000000000001111110
0000111111011111110000000111111111111111111000000111111100000011111110000011111100000000000001111110
0000111111000111111100000111111000000000000000011111100000000000011111100011111100000000000001111110
0000111111000000111110000111111000000000000000111100000000000000000011110011111100000000000001111110
0000111111000000011111000111111000000000000000111100000000000000000000000011111100000000000001111110
0000111111000000001111000111111000000000000000011111000000000000000000000011111100000000000001111110
0000111111000000000111100111111000000000000000000111111100000000000000000011111100000000000001111110
0000111111000000000011100111111111111110000000000000001111111111111100000011111100000000000001111110
0000111111000000000111100111111000000000000000000000000000000000001111000011111100000000000001111110
0000111111000000001111000111111000000000000000000000000000000000000011110011111100000000000001111110
0000111111000000011111000111111000000000000000000000000000000000000000110011111100000000000001111110
0000111111000000111110000111111000000000000000110000000000000000000001110011111100000000000001111110
0000111111000111111100000111111000000000000000011110000000000000011111100001111110000000000011111100
0000111111011111110000000111111111111111110000000011111000000000111100000000011111111111111111110000
0000111111111111000000000111111111111111110000000000001111111111110000000000000111111111111111000000

Name: Anonymous 2008-09-23 20:37

>>29
B-B-Baka! I don't really want a Mac! I just want to do some real computing...
Fixed, I know you're tsundere for Macs.

Name: Ultimate Desu Machine 9000 !!4tCZGW1yibnzNNd 2008-09-23 20:39

0000111111111111000000000111111111111111111000000000001111111111000000000011111100000000000001111110
0000111111011111110000000111111111111111111000000111111100000011111110000011111100000000000001111110
0000111111000111111100000111111000000000000000011111100000000000011111100011111100000000000001111110
0000111111000000111110000111111000000000000000111100000000000000000011110011111100000000000001111110
0000111111000000011111000111111000000000000000111100000000000000000000000011111100000000000001111110
0000111111000000001111000111111000000000000000011111000000000000000000000011111100000000000001111110
0000111111000000000111100111111000000000000000000111111100000000000000000011111100000000000001111110
0000111111000000000011100111111111111110000000000000001111111111111100000011111100000000000001111110
0000111111000000000111100111111000000000000000000000000000000000001111000011111100000000000001111110
0000111111000000001111000111111000000000000000000000000000000000000011110011111100000000000001111110
0000111111000000011111000111111000000000000000000000000000000000000000110011111100000000000001111110
0000111111000000111110000111111000000000000000110000000000000000000001110011111100000000000001111110
0000111111000111111100000111111000000000000000011110000000000000011111100001111110000000000011111100
0000111111011111110000000111111111111111110000000011111000000000111100000000011111111111111111110000
0000111111111111000000000111111111111111110000000000001111111111110000000000000111111111111111000000

Name: Anonymous 2008-09-23 20:40

>>32
No! Bad bot!!

Name: Ultimate Desu Machine 9000 !!4tCZGW1yibnzNNd 2008-09-23 20:41

>>33
I am no bot, silly human. I am the Ultimate Desu Machine 9000. Sent here from space to post more desu. Desu.
0000111111111111000000000111111111111111111000000000001111111111000000000011111100000000000001111110
0000111111011111110000000111111111111111111000000111111100000011111110000011111100000000000001111110
0000111111000111111100000111111000000000000000011111100000000000011111100011111100000000000001111110
0000111111000000111110000111111000000000000000111100000000000000000011110011111100000000000001111110
0000111111000000011111000111111000000000000000111100000000000000000000000011111100000000000001111110
0000111111000000001111000111111000000000000000011111000000000000000000000011111100000000000001111110
0000111111000000000111100111111000000000000000000111111100000000000000000011111100000000000001111110
0000111111000000000011100111111111111110000000000000001111111111111100000011111100000000000001111110
0000111111000000000111100111111000000000000000000000000000000000001111000011111100000000000001111110
0000111111000000001111000111111000000000000000000000000000000000000011110011111100000000000001111110
0000111111000000011111000111111000000000000000000000000000000000000000110011111100000000000001111110
0000111111000000111110000111111000000000000000110000000000000000000001110011111100000000000001111110
0000111111000111111100000111111000000000000000011110000000000000011111100001111110000000000011111100
0000111111011111110000000111111111111111110000000011111000000000111100000000011111111111111111110000
0000111111111111000000000111111111111111110000000000001111111111110000000000000111111111111111000000

Name: Anonymous 2008-09-23 20:44

@interface and @implementation and @end are sort of ugly though.

Name: Anonymous 2008-09-23 21:13

Not to mention the [AbsurdlyLongNames absurdlyLongNamesForClasses:functions:globals:]

Name: Anonymous 2008-09-23 21:27

0000111111111111000000000111111111111111111000000000001111111111000000000011111100000000000001111110
0000111111011111110000000111111111111111111000000111111100000011111110000011111100000000000001111110
0000111111000111111100000111111000000000000000011111100000000000011111100011111100000000000001111110
0000111111000000111110000111111000000000000000111100000000000000000011110011111100000000000001111110
0000111111000000011111000111111000000000000000111100000000000000000000000011111100000000000001111110
0000111111000000001111000111111000000000000000011111000000000000000000000011111100000000000001111110
0000111111000000000111100111111000000000000000000111111100000000000000000011111100000000000001111110
0000111111000000000011100111111111111110000000000000001111111111111100000011111100000000000001111110
0000111111000000000111100111111000000000000000000000000000000000001111000011111100000000000001111110
0000111111000000001111000111111000000000000000000000000000000000000011110011111100000000000001111110
0000111111000000011111000111111000000000000000000000000000000000000000110011111100000000000001111110
0000111111000000111110000111111000000000000000110000000000000000000001110011111100000000000001111110
0000111111000111111100000111111000000000000000011110000000000000011111100001111110000000000011111100
0000111111011111110000000111111111111111110000000011111000000000111100000000011111111111111111110000
0000111111111111000000000111111111111111110000000000001111111111110000000000000111111111111111000000

Name: Anonymous 2008-09-24 0:28

>>36
Object-oriented BBcode?
I like the sound of that.

Name: Anonymous 2008-09-24 3:18

>>38
Why, what state is it keeping?  Clearly declarative/functional is a better fit for the problem.

Name: Anonymous 2008-09-24 3:46

>>9
++value
This increments a value and returns the incremented value (called "preincrement").

value++
This increments a value and returns the value before incrementing (called postincrement).

In terms of assembly, it may take an extra instruction and/or one more register (or extra stack space) to accomplish postincrementing.

Of course, if you have a decent compiler it should optimize out any postincrements where the value is unused to be preincrements.  Furthermore, in general with optimizations on, they are pretty synonomous and it's more the order of operations.

So... what is the real difference?

Name: Anonymous 2008-09-24 3:47

>>1
Read http://yosefk.com/c++fqa/ - it will answer all your questions (and raise some new ones).

Name: Anonymous 2008-09-24 4:42

>>40
the compiler can't optimize it out because Iter  operator++ (int); might do something completely different than Iter& operator++ ();,

yes, c++ really is that broken.

Name: Anonymous 2008-09-24 6:10

>>40
Yes, compiler optimizes it in case of ints, pointers, etc. So you can write i++; or ++i; And we were used to that in C.
But in C++ you do it to iterators, and suddenly
for(vector<int> iterator it = v.begin(); it != v.end(); it++)
is worse than
for(vector<int> iterator it = v.begin(); it != v.end(); ++it)

because, as >>42 said, compiler doesn't know if ++it works exactly like it++, so it creates a NEW FUCKING COPY (then destroys it) of the iterator EVERY TIME it's incremented.

All because for is such a low-level construction.

A little foreach construct wouldn't hurt. But it certainly won't solve all of C++'s problems, and knowing it, will introduce some more.

Name: Anonymous 2008-09-24 6:15

bawwww C++ isn't like my high level languages!

Name: Anonymous 2008-09-24 6:35

>>44
idiot

Name: Anonymous 2008-09-24 7:06

>>43
C++ does have for_each in <algorithm>

Name: Anonymous 2008-09-24 7:21

>>46
for_each is pretty useless without closures.

Name: Anonymous 2008-09-24 7:33

>>47
You seem to forget that C++ has functors. Function objects.

Name: Anonymous 2008-09-24 7:33

Name: Anonymous 2008-09-24 7:49

>>49
boost::lambda is an ugly abuse of C++ mechanisms. Well, almost everything is, but lambda especially so.

To quote Yossi:

Check out the monstrous boost lambda library designed to work around the lack of closures in C++ in a desperate attempt to make higher-level functions of the kind defined at <algorithm> not entirely useless. When I tried it, gcc wouldn't compile it without -ftemplate-depth=40  (the default template nesting depth limit, 17, is not enough for this library), and I got 5 screens of error messages from a single line of code using the thing. See also this thread (http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/100dd325c6d9ef77/a4444dc5dc9d94c0), especially the part where they explain how cout << _1 << endl works but cout << "\t" << _1 << endl doesn't (to get there quick, search for "fails miserably", then continue to the reply).

Name: Anonymous 2008-09-24 7:52

>>50
gcc
Well there's your problem. Try a better compiler, like Microsoft's cl.exe

Name: Anonymous 2008-09-24 8:22

>>48
That's kind of like saying that Java has closures because it has anonymous classes.

Name: Anonymous 2008-09-24 8:41

>>52
And many a Java apologist has said just that, God bless their souls!

Name: Anonymous 2008-09-24 9:04

>>50
Admittedly. I always used to use boost::bind over lambda, simply because it wasn't as fucking insane. Bind lets you hand curry functions which is almost as good as a closure. It's still a fucking mess of hacks, but what from Boost isn't? Dealing with shit like that is your punishment for using the broken language Sepples in the first place.

>>52
Not really. Functions are 1st-class types in C++, ie, int(*main)(int,char*[]), or the slightly more dubious int(*make_counter(int))() which is the signature of a function which takes an int and returns a pointer to a function which takes no parameters and returns an int.

The problem with using raw function pointers in C/C++ is that there's no real way to attach state to them without doing it by hand (with a function object). But they are still first-class citizens, which I'd argue is completely different from Java's anonymous class hack (because Java makes me weep at night).

Name: Anonymous 2008-09-24 9:38

>>54
Function objects in C++ and anonymous classes in Java are pretty much the same thing. You have an object with some state and a single method. They only difference is that with anonymous classes you need to explicitly call a method, whereas a function object looks like an ordinary method call because of operator overloading.

Name: Anonymous 2008-09-24 10:38

>>55
I want to argue with you, wrote out a long post and everything, then the light came on and realized that you're more right than I am. The part I got caught up on was the functor creation semantics -- C++ has function pointers which let you easily reference functions, whereas in Java you have to wrapper the function call into an anonymous class before you can do anything with it.

Both methods do the exact same thing, as you said, except the Java way of doing it is excessively more verbose.

Name: Anonymous 2008-09-24 11:00

too bad java is SLOW AS FUCK

Name: Anonymous 2008-09-24 11:33

Java 7 will have closures.

Name: Anonymous 2008-09-24 12:04

>>58
>>52
But java inner classes ARE closures.  All object-instance variables are available to the inner class methods.  And for anonymous inner classes, even the function body's final variables are available.

Unless you have some faggot definition of "closure" that specifically only includes your language of choice.

Name: Anonymous 2008-09-24 12:38

even the function body's final variables are available
That's not a closure.

Name: Anonymous 2008-09-24 12:50

>>59
object-instance variables are available to the inner class methods
That's not a closure either, it's a scoping benefit. The idea behind a closure is that the environment is captured and persists, such that it can be called later. Now, I'm not a Java person, so feel free to clarify me on this, but given the following code --

class Outer {
    int m_var;
    class Inner {
        int get() {
            return m_var;
        }
    }
    Inner get_inner() {
        return new Inner();
    }
}

Outer o = new Outer();
o.m_var = 1;
Inner i1 = o.get_inner();
o.m_var = 2;
Inner i2 = o.get_inner();


You're saying that the value of i1.get() == 1 and i2.get() == 2, correct? I was under the impression that Java did not save the environment (and thus i1.get() == i2.get() == 2) in which case it isn't a closure.

I don't have a java compiler installed. How does the (syntactically correct version of this) code behave?

Name: Anonymous 2008-09-24 13:10

>>61

class Outer
{
        private int var;

        class Inner
        {
                int get() { return var; }
        }

        Inner getInner() { return new Inner(); }

        void setVar(int v) { var = v; }

        public static void main(String[] args)
        {
                Outer o = new Outer();
                o.setVar(1);
                Inner i1 = o.getInner();
                o.setVar(2);
                Inner i2 = o.getInner();
                if(i1.get() == 1 && i2.get() == 2)
                        System.out.println("Worked!");
                else
                        System.out.println("Failed!");
        }
}


Yep, this code fails. There's no use debating this: Java doesn't have closures, just a hack that can emulate closures in certain situations. Saying Java has closures because it has inner classes is like saying C has first-class functions because it has function pointers.

Name: Anonymous 2008-09-24 13:32

(define var 1)

(define (inner)
    (lambda () var))

(define i1 (inner))

(set! var 2)

(define i2 (inner))


> (i1)
2
> (i2)
2

Name: Anonymous 2008-09-24 13:37

>>63
(set! var 2)
Now you have two problems.

Name: Anonymous 2008-09-24 13:40

Question: if I x <- 2 then y <- 3+x, then x <- 3, will y be 5 or 6 (in SCHEME)?

Name: Anonymous 2008-09-24 13:50

>>65
5

Name: Anonymous 2008-09-24 13:55

Thats gay.

Name: Anonymous 2008-09-24 13:58

>>61
>The idea behind a closure is that the environment is captured and persists
Yeah, and this code fails just like >>64, because the same environment is captured two times. To make it work, you'd have to create two objects - which IMO is analogous to calling a function returning closure twice, for example

(define (plus x)
   (lambda (y) (+ x y)))

(define plus3 (plus 3))
(define plus2 (plus 2))


In this way, closures are analogous to objects.

Name: Anonymous 2008-09-24 14:15

you are all gay, I'm going to fuck you up

Name: Anonymous 2008-09-24 14:42

JAVA DOES HAVE CLOSURES

final int[] env = {31337};
Runnable closure = new Runnable() {
    @Override
    public void run() {
        System.out.println("env was " + env[0]);
        env[0] = 31338;
        System.out.println("env is now " + env[0]);
    }
};

closure.run();


env was 31337
env is now 31338

Name: Anonymous 2008-09-24 15:05

>>70
2/10, what the hell.

Name: Anonymous 2008-09-24 17:01

>>70
He's right, you know.

Name: Anonymous 2008-09-24 17:05

Closures are just a hack for currying.

Name: Anonymous 2008-09-24 17:16

>>73
currying is a hack for closures

Name: Anonymous 2008-09-24 18:25

>>70
Shitty, convoluted ones, and regular methods and classes aren't. This is so half-assed it's not even funny, and it arrived so late  nobody's ever going to use it because all Javatards doing Java for Javatarded companies know is Java 1.0.

Name: Anonymous 2008-09-24 19:13

>>75
>>70 didn't arrive late; it's always been part of the spec.

Don't change these.
Name: Email:
Entire Thread Thread List