Live data from Hacker News

In the C++ bag of tricks: scoped locks

blog.skanev.org

51–56 of 56 posts

Re: In the C++ bag of tricks: scoped locks

#51
post #31

What about: #define LOCKED(lk) for(int i=lk_lock(lk); i == 0; lk_unlock(lk), i++) Probably better to test for 0 exactly, in case it fails. You don't want it to unlock twice just because it returns -1.

This is so wrong on so many levels.

It's not any worse than what was suggested in the linked article...

Re: In the C++ bag of tricks: scoped locks

#52
post #11

Earlier quoted context omitted.

Which is mostly due to lack of education. If you don't ever spent time learning, but just coding, you don't know better. And sometimes it's all too easy to get thrapped into it due to deadlines and whatnot. A former collegue of mine, unfortunately, was the best example: programmed for like 15 years years and still wrote like it was all 'C with classes' (not that there ever was such a thing). You know, writing declara…

There was a C with Classes. http://www.stroustrup.com/bs_faq.html#invention

There is no reason to code in 2014 as if CFront was just released today.

Re: In the C++ bag of tricks: scoped locks

#53
post #40
post #11

Earlier quoted context omitted.

Which is mostly due to lack of education. If you don't ever spent time learning, but just coding, you don't know better. And sometimes it's all too easy to get thrapped into it due to deadlines and whatnot. A former collegue of mine, unfortunately, was the best example: programmed for like 15 years years and still wrote like it was all 'C with classes' (not that there ever was such a thing). You know, writing declara…

C with classes is what the google c++ style guide mandates: http://google-styleguide.googlecode.com/svn/trunk/cppguide.x... No exceptions, no boost, no lambda, no rtti, streams only for logging, avoid operator overloading, etc.

I don't agree with Google's style guide, besides they are not perfect.

Re: In the C++ bag of tricks: scoped locks

#54
post #40

Earlier quoted context omitted.

C with classes is what the google c++ style guide mandates: http://google-styleguide.googlecode.com/svn/trunk/cppguide.x... No exceptions, no boost, no lambda, no rtti, streams only for logging, avoid operator overloading, etc.

The Google C++ style guide has its quirks, but describing it as "C with classes" is flat out wrong. > no boost Not true, select parts of Boost are available. > no lambda The C++11 features are being rolled in gradually. Lambda expressions are now permitted. > no rtti The guide says "avoid RTTI" and urges the developer to come up with a different design. This is very much in line with C++ best practice overall. There'…

Version 3.274 says:

Do not use lambda expressions, or the related std::function or std::bind utilities.

Re: In the C++ bag of tricks: scoped locks

#55

Earlier quoted context omitted.

C++ has variable shadowing, so that works correctly. for (int i = 0; i prints hello 25 times.

Oh right. My brain was stuck in another language. Wow, I forgot how much I'd forgotten about C++.

Actually that's just C (name nesting)

Re: In the C++ bag of tricks: scoped locks

#56
post #54

Earlier quoted context omitted.

The Google C++ style guide has its quirks, but describing it as "C with classes" is flat out wrong. > no boost Not true, select parts of Boost are available. > no lambda The C++11 features are being rolled in gradually. Lambda expressions are now permitted. > no rtti The guide says "avoid RTTI" and urges the developer to come up with a different design. This is very much in line with C++ best practice overall. There'…

Version 3.274 says: Do not use lambda expressions, or the related std::function or std::bind utilities.

It's unfortunately not synched with the internal version.
Post reply on HN