If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
![]() |
|
|
#51 |
|
Member
Join Date: Jan 2010
Posts: 378
|
You have to think a bit different in C++ than in perl and you're also much nearer the hardware, but you'll eventually write shorter code than that if you continue exercising.
|
|
|
|
|
|
#52 | |
|
Member
Join Date: Apr 2007
Location: Australia
Posts: 668
|
Quote:
But i haven't really moved past C yet. I figured it's worth writing a bit of code to get myself familiar. Then move onto the more complex c++ paradigms. I guess at that point before i get to ingrained with bad practices it would be worth learning how to write code that's intrinsically parallel. I guess another useful thing to do might be to write some simple code compile it and then decompile it and see what it did to create efficient machine code. |
|
|
|
|
|
|
#53 |
|
Darlek ******
Join Date: Jun 2004
Posts: 9,674
|
Ahh, yes the c++ programmers habit of trying to cram as much on 1 line as possible
__________________
Guardian of the Most holy Two Terabytes of Gaming Goodness™ |
|
|
|
|
|
#54 |
|
Heteroscedasticitate
Join Date: Mar 2005
Posts: 2,362
|
Learning C before C++ is a sure way to dangerous territory (yes, I know Unis and a throng of books do that, and show you naked ptrs and arrays before they show you vectors). My humble opinion is that for your goals it'd be better to employ one of the better C++ learning books, for example Koenig's Accelerated C++ or Lippman's Essential C++...if C++ is your focus.
__________________
Donald Knuth: Science is what we understand well enough to explain to a computer. Art is everything else we do. |
|
|
|
|
|
#55 |
|
Heteroscedasticitate
Join Date: Mar 2005
Posts: 2,362
|
Davros, I appreciate lulz as much as the next guy, but beyond a certain threshold just lulzing for the lulz of lulz turns into noise. Moreover, the premise of the thread is serious, whereas "Teach yourself XYZ in 24 hours" is not.
__________________
Donald Knuth: Science is what we understand well enough to explain to a computer. Art is everything else we do. |
|
|
|
|
|
#56 | |
|
Member
Join Date: Apr 2007
Location: Australia
Posts: 668
|
Quote:
|
|
|
|
|
|
|
#57 | |
|
Heteroscedasticitate
Join Date: Mar 2005
Posts: 2,362
|
Quote:
Also Lippman's C++ Primer 5th Ed. is supposed to come out soon and it's supposed to be fully C++11, but that's even more chunky and I'm not sure you'd care to go through so much, whereas Accelerated C++ and Essential C++ are pretty slim at under 300 pages (last time I checked). Basically, I believe that Bjarne is right when he talks about how modern C++ should be taught / written, and starting from C doesn't necessarily give you the most bang for the buck when aiming to learn C++.
__________________
Donald Knuth: Science is what we understand well enough to explain to a computer. Art is everything else we do. |
|
|
|
|
|
|
#58 |
|
Member
Join Date: Apr 2007
Location: Australia
Posts: 668
|
Bought a copy of Accelerated C++ , did a couple of chapters last night. After the very first hello world program it started using data types and operations i haven't used yet. The way the book explains side effects and the semicolon confused me a little but it seems very good and you are right its not an "intermediate level book at all". At least so far.
|
|
|
|
|
|
#59 |
|
Member
Join Date: Apr 2007
Location: Australia
Posts: 668
|
i've been going through Accelerated C++ and one thingy i have noticed without going into to much detail is the writers constant use of "constant". Is there any other advantage to it other then to stop yourself overwriting the initial value?
cheers |
|
|
|
|
|
#60 |
|
Moderator
Join Date: Feb 2002
Location: Redmond, WA
Posts: 3,342
|
It establishes a contract in the interface, i.e. when I look at the function definition in the header file I know that the function doesn't change a value.
Theoretically it gives the compiler an opportunity to do optimizations, practically this is rarely actually true. "const" is one if the least well though out parts of C++, the problem is if you're not absolutely const correct at the bottom, you run into issues being const correct above. It's not uncommon on larger projects to notice a function argument ought to be const, try and make the change, spend an hour or more trying to fix the fallout , then just revert the change because you end up fixing half the code base. Then you run into the issue with member functions which are semantically const, but not actually const, the classic example being a member function that caches a result. Of course that is what the mutable keyword is for... IMO everything should be const unless it's declared mutable. In practice I consider myself a const pragmatist, I'll declare it the way it should be unless it's painful to make the changes required. |
|
|
|
|
|
#61 |
|
Darlek ******
Join Date: Jun 2004
Posts: 9,674
|
If Ive got this right (sorry im a pascal programmer) mutable allows a constant to be changed
Thats bloody stupid...
__________________
Guardian of the Most holy Two Terabytes of Gaming Goodness™ |
|
|
|
|
|
#62 |
|
Moderator
Join Date: Feb 2002
Location: Redmond, WA
Posts: 3,342
|
Mutable is there for the specific reason I gave.
In the case of a const member function, the semantic is that it does not modify class state. I.e. it's a getter of some sort. However it is common in the implementation of a getter to cache computed results, since the cache is part of the class state, without mutable that would mean that you could not declare the member const and no function above it could take a const value. In practice that means that trying to be const correct in the rest of the application is now impossible. It's the difference between the interface semantics and the implementation. As I said in practice people fall in to two camps, ignore const entirely, or try and do the right thing until it becomes impractical. |
|
|
|
|
|
#63 |
|
Senior Member
Join Date: Dec 2004
Posts: 1,765
|
mutable and const cant be specified for the same variable. mutable denotes its not changing the (formal) state of an object (a const function call with the same parameters is guaranteed to have the same result aslong as you dont change the state), think of cached views.
for the compiler this allows certain optimizations, consider: Code:
for (SomeIterator it = container.begin(); it != container.end(); ++it) {/*blahblah*/}
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|