language-features

C++: Adding and redefinition of default arguments in real world

大城市里の小女人 提交于 2019-12-03 07:15:00
问题 There is a possibility to add or redefine default arguments of a function in C++. Let's look at the example: void foo(int a, int b, int c = -1) { std::cout << "foo(" << a << ", " << b << ", " << c << ")\n"; } int main() { foo(1, 2); // output: foo(1, 2, -1) // void foo(int a, int b = 0, int c); // error: does not use default from surrounding scope void foo(int a, int b, int c = 30); foo(1, 2); // output: foo(1, 2, 30) // void foo(int a, int b, int c = 35); // error: we cannot redefine the

Confused by Boxing. Casting -1 to Int64 throws InvalidCastException

半世苍凉 提交于 2019-12-03 06:20:14
Ok I must be overlooking something extremely simple but I am lost. Given this object val = -1; var foo = (Int32)(val); var bar = (Int64)(val); The cast to Int64 throws and InvalidCastException. I recognize this is related to some strangeness with boxing but I don't understand the reasoning. From what I understand val is boxed as Int32 on the first line. Then when I try to cast as something other than Int32 InvalidCastException is thrown. I suppose this means that I am trying to unbox val as Int64 when it is actually an Int32? Still seems strange. Couldn't the cast unbox the value and then try

Python: How to pass more than one argument to the property getter?

放肆的年华 提交于 2019-12-03 06:11:24
问题 Consider the following example: class A: @property def x(self): return 5 So, of course calling the a = A(); a.x will return 5 But imagine that you want to be able to modify the property x. This way, for example: class A: @property def x(self, neg = False): return 5 if not neg else -5 And call it with a = A(); a.x(neg=True) That will raise a TypeError: 'int' object is not callable , that is quite normal, since our x is evaluated as 5 . So, I would like to know how one can pass more then one

Question regarding implicit conversions in the C# language specification

和自甴很熟 提交于 2019-12-03 06:01:49
Section 6.1 Implicit conversions defines an identity conversion thusly: An identity conversion converts from any type to the same type. This conversion exists such that an entity that already has a required type can be said to be convertible to that type. Now, what is the purpose of sentences such as these? (In §6.1.6 Implicit reference conversions) The implicit reference conversions are: [...] From any reference-type to a reference-type T if it has an implicit identity or reference conversion to a reference-type T 0 and T 0 has an identity conversion to T . and: (In §6.1.7 Boxing conversions)

Anonymous type and tuple

谁都会走 提交于 2019-12-03 05:36:43
问题 What is the difference between anonymous type and tuple? 回答1: Anonymous types have property names which carry more information, for tuples you don't have this. You can't use anonymous types as return values and parameters though and you can with tuples. An example of when a tuple is nice is when you want to return multiple values. @Petar Minchev mentions this link which gives a good example. You may want a Find() method that returns both an index and the value. Another example would be the

Should I use C++0x Features Now?

我与影子孤独终老i 提交于 2019-12-03 04:38:53
With the official release of VS 2010, is it safe for me to start using the partially-implemented C++0x feature set in my new code? The features that are of interest to me right now are both implemented by VC++ 2010 and recent versions of GCC. These are the only two that I have to support. In terms of the "safety" mentioned in the first sentence: can I start using these features (e.g., lambda functions) and still be guaranteed that my code will compile in 10 years on a compiler that properly conforms to C++0x when it is officially released? I guess I'm asking if there is any chance that VC++

What features should Java 7 onwards have to encourage switching from C#? [closed]

冷暖自知 提交于 2019-12-03 04:17:00
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . C# has a good momentum at the moment. What are the features that you would need to have in order to switch (or return) to Java? It

What advantages does Scala have over Java for concurrent programming?

风流意气都作罢 提交于 2019-12-03 02:04:10
How can scala make writing multi-threaded programs easier than in java? What can scala do (that java can't) to facilitate taking advantage of multiple processors? The rules for concurrency are 1 avoid it if you can 2 share nothing if you can 3 share immutable objects if you can 4 be very careful (and lucky) For rule 2 Scala helps by providing a nicely integrated message passing library out of the box in the form of the actors. For rule 3 Scala helps to make everything immutable by default. For rule 4 Scala's flexible syntax allows the creation of internal DSL's making it easier and less wordy

Should I prefer static methods in C#

坚强是说给别人听的谎言 提交于 2019-12-03 01:37:56
Having spent a bit of time learning about functional programming, it's becoming more and more natural for me to want to work with static methods that don't perform any mutation. Are there any reasons why I should curb this instinct? The question I find a bit odd, because static methods and methods that perform no mutations are two orthogonal classifications of methods. You can have mutating static methods and nonmutating instance methods. For me, it has become more and more natural to combine functional and oo programming; I like instance methods that perform no mutations. Functional

What unique features does Firebug have that are not built-in to Firefox?

雨燕双飞 提交于 2019-12-03 00:30:00
问题 I just cleaned my Firefox addons and wondered: Which features does Firebug have that make it unique? Which features are available in both Firebug and the Firefox Developer Tools? 回答1: Firefox's native developer tools have come a long way since this question was written. The differences have mainly reduced to the following points: Can't stop the script execution on DOM mutations, XHRs, or cookie changes. XPaths can't be copied. Missing an events side panel in the Inspector (though events are