« first day (642 days earlier)      last day (4305 days later) » 

5:00 PM
@Drise Filter is a better word.
 
@Regexident Y U NO USE IDEONE?
 
Y U NO star my Oh Snap! Comment... It;s good.... :-)
 
@Regexident That doesn't do what you think it does.
Sounds like you will benefit from a good C++ book.
1343
Q: The Definitive C++ Book Guide and List

grepsedawkThis question attempts to collect the few pearls among the dozens of bad C++ books that are released every year. Unlike many other programming languages, which are often picked up on the go from tutorials found on the Internet, few are able to quickly pick up C++ without studying a good C++ book...

 
This just in, the uneasy language wars truce may be about to fall apart.
 
second time I see this question posted today
 
user784668
5:01 PM
@Regexident Your problem is that you don't know C++.
 
If I'm not mistaken there is nothing in the standard that says iterators may not throw anything on incrementing/crementing, right?
 
@Regexident You claim there's code required before superclass constructor. C++ has simple ways to handle that, that you don't seem to know about.
@nightcracker right
 
Also oh gods malloc.
 
Let's all barrage him with Y U NO KNOW C++?
 
@R.MartinhoFernandes Why? You really should fix this
 
5:02 PM
@Nils Fix what?
 
ur sleep
 
Hello
 
Hello Robin
 
What's ur?
 
@Nils Because I can't do stuff if I'm not awake?
 
5:02 PM
@MooingDuck: mind to throw me a name/term to google for (simple C++ handling solution you're talking about)?
 
@Regexident initializer list + function call
 
@Regexident: python
lol
 
@R.MartinhoFernandes heh I don't think you need to do that much stuff
if so then ur doing too much
 
Also, don't my Hyperrect mutable, because mutable hyperrects are not substitutable with mutable hypercubes.
 
Anyone else going to see me tonight?
 
5:04 PM
@Regexident ideone.com/68Pdd
 
Liskov substitutability principle.
 
@Regexident and for constructors with the same parameters, simply use the "named constructor idiom"
 
// Hyperrect::dimensions is std::vector<double>
Hyperrect::Hyperrect(std::initializer_list<double> dimensions) : dimensions(dimensions) {}
Hyperrect::Hyperrect(std::vector<double> dimensions) : dimensions(dimensions) {}
Hypercube::Hypercube(double dimensions, int dimensionality) : Hyperrect(std::vector<double>(dimensions, dimensionality)) {} // or another overload for T, int
Hypercube::Hypercube(double volume, int dimensionality) : Hypercube(DimensionsForVolume(volume), dimensionality) {}
 
@Nils Y U USE SILLY SMS SPEAK?
 
Is it true that XP64 is a lot looser on all the genuine advantage crap?
 
5:05 PM
Oh, right, same types. Then strong typedef them.
I have a feeling it's a silly class anyway.
I already noticed thaaaaaaat.
 
I already noticed you noticed thaaaaaaat.
 
Fiiiiine.
 
loooooolllllllllllll
 
Baaaaaaatttmaaaan
 
tadadumdum
 
5:07 PM
@MooingDuck: Thanks, init lists & function call actually was my first thought, but I feared there being a memory leak as DimensionForVolume would need to return a mallocated array.
 
@MooingDuck This should be fun. I have a field numthreads. It could be an integer, or it could be "AUTO". I'm thinking something like the custom_complex...
 
@Regexident memory leaks should not be your concern if you use standard containers.
 
why use regex? it tends to be slow
 
@R.MartinhoFernandes @ecatmur: yeah, should have gone with containers in the first place I guess. Thanks, guys.
 
5:09 PM
@Regexident 1. Don't use arrays. 2. Don't use malloc.
If you ever write malloc in C++ code slap yourself and then delete your project.
4
 
@CatPlusPlus shouldn't that be free your project?
 
@ecatmur No, UB is all you deserve.
 
@CatPlusPlus: Had the malloc, etc as the code actually was written in C originally. Legacy remainder. ;)
Thus porting to C++ for the sake of sanity.
 
@CatPlusPlus You forgot to:
 
question: when is it better to use multithreading and when is it better to just make the algorithm better?
 
5:11 PM
error<digestive_system> up("pizza");
   throw up;
Or replace pizza with any other thing that can fit into a mouth.
 
@IAmBatman when you've profiled your code to determine that there is a performance problem.
 
user784668
@CatPlusPlus I've used malloc when writing my own allocator. What now?
 
@Fanael You suck.
 
nothing wrong with using malloc in C++
 
Real programmers use sbrk to write allocators.
 
5:13 PM
or mmap(NULL)
 
@IAmBatman Outside of very specific use case, everything is wrong with using malloc in C++.
 
@CatPlusPlus sbrk and C++ is not easy.
 
user784668
@CatPlusPlus sbrk sucks.
 
GCC uses it for some shit for exceptions.
And borked my allocator :S
 
sbrk is inherently noncooperative; leave it to the implementation and use anonymous mmap.
 
5:14 PM
LEt me get this straigth , you can actually tell , if a c++ developer is well trained by just analyzing his coding style ?
 
user784668
POSIX sucks, use VirtualAlloc.
 
In many cases, yes.
 
@ecatmur Yeah, I learned it the hard away.
 
EVERYTHING SUCKS!!!
 
Anyway, you can return an mmaped page; you can't return sbrk without re-execing.
 
user784668
5:14 PM
Or NtAllocateVirtualMemory if you're brave enough.
 
@LeandroArielPezzente Unless they're faking it.
 
@CatPlusPlus "new" allocates memory and creates an object in that memory location, sometimes this isn't desirable
 
@IAmBatman not for primitive types
char *buf = new char[sizeof(A)]; // NOT RECOMMENDED; DO NOT COPY THIS CODE
 
What situations do you want "non-objects"?
Also vector.
 
std::vector<char>.
 
5:16 PM
generally if I am porting C code to C++, I leave the mallocs be
 
if I am starting new C++ code I use new
 
I don't use new. I'm the awesomest.
 
user784668
@ecatmur A a;
 
Why are you bothering porting C code to C++, if it's not really C++?
 
5:16 PM
@MooingDuck I think this will work.
  if (!(file >> '=' >> obj.first.numthreads))
  {
    std::string autothread;
    file.clear();
    if (!(file >> autothread))
      obj.second->errorH(symbol + " is incorrectly formatted", 1);
    else
      if (autothread == AUTO)
        obj.first.autoThreading = true;
      else
        obj.second->errorH(symbol + " is incorrectly formatted", 1);
  }
  else
    obj.first.autoThreading = false;
 
Does Boost Library Implements a IOC Design Pattern ?
 
@CatPlusPlus There are plenty of cases
 
Not really, you're just writing shitty code.
 
user784668
@CatPlusPlus Because compiling C as C++ gives you 10 points of Fortify Kewlness.
 
meh shitty code
 
5:18 PM
did they make any significant changes to new recently
 
no
you don't need to use it, just abstain from using it
 
Allocating buffers is not a common use-case, anyway.
Well, for objects.
 
what specific case were you thinking of cat plus plus
for using malloc in C++
 
@Regexident use containers, not malloc
 
Needs to allocate buffers => Makes a freaking buffer class.
 
5:19 PM
RAII those buffers, biatches
 
@Drise what's an AUTO?
 
@MooingDuck: fixing that right now ;)
 
Needs to allocate buffers => Smears new or malloc all over? WTF?
 
@MooingDuck enum, I'm guessing
 
@MooingDuck it's a car in German
 
5:20 PM
@IAmBatman None.
Well, allocators, maaaybe.
 
oh, maybe not
 
If you suck.
 
user784668
@TonyTheLion In Polish, too.
 
@Drise oh, I get it
 
What if you don't know how many Objects of given class will need to be instantiated at compile time? Seems you'd want to use new... or would you just use a vector that contains the Objects?
 
5:20 PM
@CatPlusPlus You said "Outside of very specific use case, everything is wrong with using malloc in C++."
what use case?
 
@JimNorton vector.
 
@IAmBatman Allocators.
 
in what sense
 
In "allocators" sense.
 
user784668
5:21 PM
vector sucks and is unsafe, don't listen to them!!!
 
in the allocator sense
 
@R.MartinhoFernandes Yeah that's what I wrote... just wanted to confirm that I've heard correctly.
 
If you don't know what allocator is, you don't use malloc.
Simple.
 
@Fanael GTFO RTFN
 
as in how are they beneficial in the allocator sense
 
5:21 PM
I never said they're beneficial.
I said you might get away with using them there.
 
ok, not wrong then
 
What.
 
WRONG WRONG WRONG
 
user784668
@TonyTheLion NO.
 
5:22 PM
but really i wouldn't use malloc for allocators, i think you are better off using new because it's type safe and can be overridden with a class
 
All those three exist for the express purpose of not using new.
 
@MooingDuck "AUTO" is a string literal.
 
@Fanael How so? What's wrong with vectors. BTW, I'm still learning C++, and don't know much, so I'm just being inquisitive here.
 
Woahhh , It actually has a container pointer for that ..
 
@R.MartinhoFernandes :-)
 
5:23 PM
@JimNorton sarcasm
 
@IAmBatman Allocators are not supposed to return objects, they're supposed to return chunks of storage.
 
@R.MartinhoFernandes that is correct
 
@MooingDuck ah
@R.MartinhoFernandes What if the Object is chunk of storage?
 
@R.MartinhoFernandes That's why I said earlier that they handle the space and don't necessarily the object
 
5:24 PM
@Drise your code could be simplified if you still have the stream in string literals code I wrote
 
@JimNorton Then it's vector<char>.
 
@IAmBatman You're better off not using new.
 
new is better than malloc generally
 
@JimNorton You can have an object that handles a chunk of storage, but that itself is an object. The point is, allocators (like malloc) don't create objects but new does.
 
right
 
5:25 PM
You very rarely ever need storage but not objects, and that's why malloc is close to useless in C++.
 
Isnt that the whole idea behind Inversion of Control Pattern ?
 
@R.MartinhoFernandes Ah ok... thanks for clarifying ... I was becoming fused.
 
new is undesirable for different reasons, though (mainly, because it's prone to leaks).
 
prone to leaks?
 
And if you need storage but not objects, you can use a char buffer.
 
5:25 PM
@IAmBatman Well yeah, that DEPENDS.
 
@IAmBatman It does nothing to avoid them.
 
If you dont set a propper destructor with a propper delete , yeap.
 
And it does all that is needed to risk them.
@LeandroArielPezzente And a proper copy constructor and copy-assignment operator.
Just use RAII handles.
 
@MooingDuck OH YEA... wait.. I'd rather you show me, I'd probably mess it up.
 
Shiite. I must begin to read my C++ book this week still.
 
5:27 PM
sometimes i see that issue where the reference is deleted but the object is not, so it just sits there in memory with no way to get it back
 
@R.MartinhoFernandes do actual proffesional developers forget to setup all that ?
 
Doesn't happen with unique_ptr, or vector, or anything else that exists so you don't have to use the damn new.
 
Oh, so I had my sleep study last night. That goop they use to attach the electrodes to your head is really hard to get out the hair.
I must have shampooed 6 times.
 
sleep study?
 
5:30 PM
@MooingDuck Hold on, I think I got it.
      if (!(file >> '=' >> "AUTO"))
      {
        file.clear();
        if (!(file >> obj.first.numthreads))
          obj.second->errorH(symbol + " is incorrectly formatted", 1);
        else
          obj.first.autoThreading = false;
      }
      else
        obj.first.autoThreading = true;
 
@JimNorton I had no hair when I went...+1
 
@LeandroArielPezzente IMO many either don't know better (shame on them); or don't even think there might be a better way (there's this myth that you have to manually micromanage your memory in C++).
 
what problem do you have? insomnia?
 
@keith.layne +1 indeed and well played sir!
 
5:31 PM
@R.MartinhoFernandes he has no idea what you're talking about
 
@IAmBatman Probably sleep apnea. I sleep, but never feel like I really sleep well. Never feel restored when I wake up.
 
do you exercise at all? i find that helps me sleep better
or sleeping an hour earlier than normal
 
@IAmBatman Well, it's not that I don't sleep, it's that I wake all the time when I stop breathing...
So I rarely go into REM sleep, which is important to restorative sleep.
 
@JimNorton just breathe, man! Breathe!
 
@rubenvb :-)
 
5:34 PM
@rubenvb They told Neo to do that too and look what happened
 
@Drise no, that's... you don't want that
 
@R.MartinhoFernandes Both Boost LIbrary and Apache C++ Library provides Garbage Collection Algorithms Implementations. I dont wheres the "micromanage C++ memory" myth sustaintibility ..
 
@LeandroArielPezzente Oh, don't try to apply reason to it.
 
@R.MartinhoFernandes you're showing an extreme lack of impatience.
 
C++ has some degree of memory management
 
5:35 PM
@keith.layne Yes, I'm not perfect.
 
maybe not as much as C
 
@LeandroArielPezzente you're lost.
 
but it's not fair to say there ISN'T any management needed
 
@MooingDuck Oh..
 
@IAmBatman you're lost.
 
5:35 PM
@keith.layne how so
 
@IAmBatman What.
 
@IAmBatman Seems like if you write correct C++, you don/t have to worry about it as the standard classes handle the memory - RAII and such.
 
@IAmBatman If you're doing it somewhere other than very localized places (i.e. building blocks), you're doing it wrong.
 
@keith.layne In what sense i am lost ?
 
@Drise imagine the line "variable 12345", that code accepts it. (missing the "=")
 
5:36 PM
I am talking about new/delete type stuff
I consider that some form of memory management, is that not correct?
 
Manually managing memory is a pain.
 
In the sense that nobody's talking about garbage collection, because it in unneccessary.
 
I only have one instance of delete in all the C++ code I've ever written.
 
@IAmBatman google RAII
 
5:37 PM
@R.MartinhoFernandes How do you clean up objects you instantiate then?
 
@R.MartinhoFernandes then you must have been an enlightened beginner.
 
@IAmBatman unique_ptr
 
@IAmBatman That single delete does that. (That one and the ones in the standard library)
 
@IAmBatman when they go out of scope - deconstructor
??
 
scope-based resource management, or whatever the right term is
 
5:38 PM
interesting
 
Oh wait, scratch that!
 
Didn't I just say that! :-)
 
I have not a single delete now.
 
when I was taught C++ in school many years ago it was all about new and delete
 
@JimNorton yes
 
5:38 PM
@MooingDuck Good point.
 
@keith.layne I was curious wheter if forgetting to do a propper memory clean up was or not a common (bad) practice.
 
I resort to default_delete<T> :P
 
@IAmBatman you were taught badly maybe, or maybe before the advent of modern C++.
 
user784668
Jul 11 at 18:39, by Fanael
@FredOverflow But with RAII you still write delete everywhere. Except it's spelled }.
 
@IAmBatman Sadly, that is common in school :S
 
5:39 PM
@LeandroArielPezzente it's not forgetting. Google RAII.
 
@R.MartinhoFernandes So is your method here this RAII?
 
@Fanael good one.
 
@IAmBatman If you hang around here for a few weeks and listen and participate you might be surprised how much you will learn about C++ idioms and best practices for the modern age of C++
 
@IAmBatman Yes.
 
@LeandroArielPezzente in C++, it's automatic. There's nothing to forget
 
5:39 PM
interesting
mind = blown. always thought it was all about new and delete
 
@IAmBatman it's all about destructors
 
that's why I was reading this conversation and laughing to myself.
 
Googling this, very interesting
 
222
A: Why does the use of `new` cause memory leaks in C++?

R. Martinho FernandesWhat is happening When you write T t; you're creating an object of type T with automatic storage duration. It will get cleaned up automatically when it goes out of scope. When you write new T() you're creating an object of type T with dynamic storage duration. It won't get cleaned up automatica...

 
5:42 PM
@LeandroArielPezzente Inversion of control is a Pattern?
 
Is RAII only a C++ thing?
do other languages do this too?
like Java, Actionscript, etc?
 
Maybe D, let me look it up.
Definitely not the pure GC languages.
 
@keith.layne I started learning C++ in this room.
 
how long ago?
 
5:44 PM
Resource Acquisition Is Initialization (RAII, sometimes RIIA) is a programming idiom used in several object-oriented languages like C++, D and Ada. The technique was invented by Bjarne Stroustrup to deal with resource allocation and deallocation in C++. In this language, the only code that can be guaranteed to be executed after an exception is thrown are the destructors of objects residing on the stack. Resource management therefore needs to be tied to the lifespan of suitable objects in order to gain automatic allocation and reclamation. They are acquired during initialization, when there ...
> C++ and D allow objects to be allocated on the stack and their scoping rules ensure that destructors are called when a local object's scope ends. By putting the resource release logic in the destructor, C++'s and D's scoping provide direct support for RAII.
 
Actually, it was by lurking in this room that I got the C++ bug.
 
Where is strncmp located?
 
Apr 18 '11 at 1:46, by Martinho Fernandes
I know C, and I know OOP. I've also done some C-with-classes stuff in the past. But now I want to learn C++ for real. I got Bjarn's book. How far can I safely skip?
 
@FredOverflow AFAIK is either a pattern of an architecture.
 
@Drise <cstring>, at least that's what the first hit on Google suggests.
 
5:45 PM
@R.MartinhoFernandes whoa, that's recent
 
@FredOverflow Yep, compiler no longer complaining.
 
string.h
 
Are there good resources for learning how to code properly? I always fear that it's too easy to learn bad habits from others if they don't know what they're doing.... this new/delete thing being a prime example
 
@R.MartinhoFernandes and you learnt templates :P
 
@JimNorton Afaik if you include <cstring> instead of <string.h> you get to say std::strncmp, but maybe it was the other way around, or maybe it didn't matter. I can never remember.
 
5:46 PM
@IAmBatman good question. I know a list of bad places :( Schools.
 
Internet tutorials, too.
 
Werent smart pointers introduced in C++11 ??
 
@IAmBatman You need good books. Most books out there suck, especially C++ books.
 
@FredOverflow: <string.h> doesn't even have to exist IIRC
 
internet tutorials tend to be wrong too though
 
5:47 PM
@LeandroArielPezzente no
 
@LeandroArielPezzente Smart pointers originated in boost and found their way into TR1 before coming standard C++11.
 
@IAmBatman Do not take anything a university tells you as "a good way". Prime example: using namespace std;
 
how can I separate the good advice from the BS if I am not qualified enough to tell them apart
 
@FredOverflow auto_ptr was C++03
 
@IAmBatman You can't. That's why you need to listen to us ;)
 
5:48 PM
@LeandroArielPezzente The unique and shared ones were put in the standard library in C++11, but only unique_ptr required new language features.
 
@FredOverflow didnt knew that , Thanks !
 
@Drise Oh no.... what's wrong with using namespace std?
 
@MooingDuck Wasn't that C++98 already?
 
@FredOverflow probably
 
@IAmBatman Hang out here.
 
5:48 PM
@LeandroArielPezzente If you read my answer linked above it contains an implementation of an automatic pointer that only uses C++98 features.
 
Anyway, auto_ptr doesn't count as a smart pointer, it's more of a dumb_pointer in my books ;)
2
 
user784668
@nightcracker It does have to. It's deprecated, but it still exists.
 
@IAmBatman It's a virus. use std:: For example: std::string. std::vector.
 
@FredOverflow it's better than a raw pointer
 
@R.MartinhoFernandes What kind of automatic pointer?
 
5:49 PM
but isn't using std:: all over the place more easily wrapped up by just including the namespace?
 
@FredOverflow It's like boost::scoped_ptr. It's just for example, and is clearly labelled as such.
 
@MooingDuck I wouldn't be so sure about that. At least you can put raw pointers into STL containers.
 
@IAmBatman It spreads like a virus. It also makes you look cool if you use std::
 
@FredOverflow true
 
what do you mean by that though?
 
5:49 PM
@IAmBatman you don't include a namespace. You can using it. But it depends.
 
@IAmBatman easy? yes. Causes problems though
 
*using, sorry
 
40
Q: Using std Namespace

paoloricardoThere seem to be different views on using 'using' with respect to the std namespace. Some say use ' using namespace std', other say don't but rather prefix std functions that are to be used with ' std::' whilst others say use something like this: using std::string; using std::cout; using std::c...

 
Going to lunch, be back in a few folks.
 
cya
 
5:50 PM
Ain't it lovely when we get the new folks already helping each other out?
4
 
@R.MartinhoFernandes I don't know about boost::scoped_ptr.
 
I always add the specific using std::whatever; after the relevant C++ include in every implementation file.
 
@FredOverflow It's like auto_ptr, or unique_ptr, but not copyable or movable.
 
so it seems to be a removal of ambiguity issue
 
@IAmBatman yes, nothing more
 
5:51 PM
@R.MartinhoFernandes Not even moveable? So only useful to release in the face of exceptions? Sounds perfect for an introductory example :)
 
i feel like I have been told lies for so long :(
 
@R.MartinhoFernandes Yes it is. I've learned so much just hanging out here asking questions and following conversations.
 
@IAmBatman half-truths
 
unplug me from the matrix, hang up my penis, take me out to pasture, and shoot me please
 
@IAmBatman You have to be strong now: the return type of main is not void, even though it's okay not to return anything explicitly!
 
5:51 PM
@FredOverflow Yep, that was the idea :)
 
I've always used int main() with a return of 0
Don't tell me that's bad practice, too?
 
That's fine. But you don't need the return 0;, it's implicit in main.
 
That's perfectly harmless.
 
@IAmBatman that's the best way
@FredOverflow don't tell people that. I'd rather have that return 0 there always
 
@MooingDuck Unless he wants to read arguments from the command line ;)
 
5:53 PM
@FredOverflow well, yes
 
I don't return from main. Stupid C-ism.
 
So you just do int main with no return? or void main?
 
@MooingDuck I don't really care about the return 0; inside main. Do whatever you please, both is correct.
int main()
{
}
 
main is magic.
 
interesting
 
5:54 PM
not really worth worrying about though
 
hmm also curious, what about declaring variables inside loops?
bad practice right?
 
21
Q: What is the proper declaration of main?

FredOverflowWhat is the proper signature of the main function in C++? What is the correct return type, and what does it mean to return a value from main? What are the allowed parameter types, and what are their meanings? Is this system-specific? Have those rules changed over time? What happens if I violate...

 
No. Maybe. Depends.
 
@IAmBatman Never use void main().
 
@IAmBatman I don't see what would be inherently wrong with that.
 
5:55 PM
@IAmBatman Depends on how expensive initialization is compared with assignment. If you're talking about ints and such, it doesn't matter at all.
 
Also never use using namespace std.
 
@IAmBatman The general rule is to "declare near first use". If the first time you use something is in the loop, then declare it there.
 
Declaring is free.
 
hmmm
 
Get your terms straight dammit.
 
5:56 PM
Except in puts("Never use using namespace std."); ;)
 
Never use puts either.
 
huh, puts...
 
I like puts. It looks so efficient ;)
 
i just use cout (and endl although sometimes just \n, not sure when to use what since they do the same thing really... just presume \n is a Cism)
 
console IO on Windows is dead slow anyways, cout won't slow it down :)
 
5:57 PM
:)
 
@CatPlusPlus Well, with objects with automatic storage duration, "declaration" necessarily implies "definition".
 
Why does PODness matter?
 
@IAmBatman Well, use \n first.
 
@R.MartinhoFernandes Gee , thanks for being so educative !
 
@IAmBatman std::endl writes \n then calls std::flush
@FredOverflow Hmm. Good point.
 
5:58 PM
what's the difference?
and why use \n first
 
I always use "\n"
it's a hell of a lot faster in synthetic benchmarks
 
Persistence Object Design ?
 
@IAmBatman std::flush makes the string write out its internal buffer immediately.
You don't always need that.
 
@EtiennedeMartel You're moving poalgosts bloo bloo bloo.
 
@IAmBatman '\n' doesn't "save" the file. endl does a "save". It's slow.
 
5:59 PM
You're crazy, :w saves file.
3
 
hm
 
70
Q: C++: "std::endl" vs "\n"

Head GeekMany C++ books contain example code like this... std::cout << "Test line" << std::endl; ...so I've always done that too. But I've seen a lot of code from working developers like this instead: std::cout << "Test line\n"; Is there a technical reason to prefer one over the ot...

 
but you still use cout yes?
 
@IAmBatman oh yeah std::cout
 
I always resort to printf for floating point numbers and hexadecimal, I simply cannot remember how to do it with std::cout :)
 

« first day (642 days earlier)      last day (4305 days later) »