coding-style

Isn't the const modifier here unnecessary? [duplicate]

混江龙づ霸主 提交于 2019-12-17 06:07:53
问题 This question already has an answer here : How can a returned object be assignable? (1 answer) Closed 6 years ago . The " Effective C++ " Item 3 says "Use const whenever possible", and it gives an example like: const Rational operator*(const Rational& lhs, const Rational& rhs); to prevent clients from being able to commit atrocities like this: Rational a, b, c; ... (a * b) = c; // invoke operator= on the result of a*b! But isn't the non-reference return value of functions allready a rvalue ?

Isn't the const modifier here unnecessary? [duplicate]

℡╲_俬逩灬. 提交于 2019-12-17 06:07:02
问题 This question already has an answer here : How can a returned object be assignable? (1 answer) Closed 6 years ago . The " Effective C++ " Item 3 says "Use const whenever possible", and it gives an example like: const Rational operator*(const Rational& lhs, const Rational& rhs); to prevent clients from being able to commit atrocities like this: Rational a, b, c; ... (a * b) = c; // invoke operator= on the result of a*b! But isn't the non-reference return value of functions allready a rvalue ?

C++ getters/setters coding style

大兔子大兔子 提交于 2019-12-17 05:36:15
问题 I have been programming in C# for a while and now I want to brush up on my C++ skills. Having the class: class Foo { const std::string& name_; ... }; What would be the best approach (I only want to allow read access to the name_ field): use a getter method: inline const std::string& name() const { return name_; } make the field public since it's a constant Thanks. 回答1: It tends to be a bad idea to make non-const fields public because it then becomes hard to force error checking constraints

Currying subtraction

南笙酒味 提交于 2019-12-17 05:05:11
问题 If we want to map a function that increases every element of a range by 1, we could write map (\x -> x + 1) [1..5] but I guess most people would just go for map (+1) [1..5] instead. But this obviously doesn't work with (-1) since that's negative one. So the first thing that came to mind was map (+(-1)) [1..5] which would make sense considering how subtraction is defined in the Prelude ( x - y = x + negate y ), but looks a bit odd to me. I then I came up with map (flip (-) 1) [1..5] This

Tools to find included headers which are unused? [closed]

一曲冷凌霜 提交于 2019-12-17 04:47:53
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I know PC-Lint can tell you about headers which are included but not used. Are there any other tools that can do this, preferably on linux? We have a large codebase that through the last 15 years has seen plenty of functionality move around, but rarely do the leftover #include directives get removed when

Tools to find included headers which are unused? [closed]

浪子不回头ぞ 提交于 2019-12-17 04:47:27
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I know PC-Lint can tell you about headers which are included but not used. Are there any other tools that can do this, preferably on linux? We have a large codebase that through the last 15 years has seen plenty of functionality move around, but rarely do the leftover #include directives get removed when

In C++, is it still bad practice to return a vector from a function?

非 Y 不嫁゛ 提交于 2019-12-17 04:39:13
问题 Short version: It's common to return large objects—such as vectors/arrays—in many programming languages. Is this style now acceptable in C++0x if the class has a move constructor, or do C++ programmers consider it weird/ugly/abomination? Long version: In C++0x is this still considered bad form? std::vector<std::string> BuildLargeVector(); ... std::vector<std::string> v = BuildLargeVector(); The traditional version would look like this: void BuildLargeVector(std::vector<std::string>& result);

Python exception chaining [duplicate]

China☆狼群 提交于 2019-12-17 04:21:14
问题 This question already has answers here : “Inner exception” (with traceback) in Python? (9 answers) Closed 4 years ago . Is there a standard way of using exception chains in Python? Like the Java exception 'caused by'? Here is some background. I have a module with one main exception class DSError : class DSError(Exception): pass Somewhere within this module there will be: try: v = my_dict[k] something(v) except KeyError as e: raise DSError("no key %s found for %s" % (k, self)) except

Haskell function composition (.) and function application ($) idioms: correct use

◇◆丶佛笑我妖孽 提交于 2019-12-17 04:12:29
问题 I have been reading Real World Haskell , and I am nearing the end, but a matter of style has been niggling at me to do with the (.) and ($) operators. When you write a function that is a composition of other functions you write it like: f = g . h But when you apply something to the end of those functions I write it like this: k = a $ b $ c $ value But the book would write it like this: k = a . b . c $ value Now, to me they look functionally equivalent, they do the exact same thing in my eyes.

Relational table naming convention [closed]

☆樱花仙子☆ 提交于 2019-12-17 04:08:32
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . I'm starting a new project and would like to get my table- and column names right from the start. For example I've always used plural in table names but recently learned singular is correct. So, if I got a table "user" and then I got products that only the user will have,