language-features

Optional named arguments without wrapping them all in “OptionValue”

萝らか妹 提交于 2019-11-29 15:19:33
问题 Suppose I have a function with optional named arguments but I insist on referring to the arguments by their unadorned names. Consider this function that adds its two named arguments, a and b: Options[f] = {a->0, b->0}; (* The default values. *) f[OptionsPattern[]] := OptionValue[a] + OptionValue[b] How can I write a version of that function where that last line is replaced with simply a+b ? (Imagine that that a+b is a whole slew of code.) The answers to the following question show how to

Catch access to undefined property in JavaScript [duplicate]

我与影子孤独终老i 提交于 2019-11-29 13:21:28
This question already has an answer here: Is there an equivalent of the __noSuchMethod__ feature for properties, or a way to implement it in JS? 5 answers The Spider-Monkey JavaScript engine implements the __noSuchMethod__ callback function for JavaScript Objects. This function is called whenever JavaScript tries to execute an undefined method of an Object. I would like to set a callback function to an Object that will be called whenever an undefined property in the Object is accessed or assigned to. I haven't found a __noSuchProperty__ function implemented for JavaScript Objects and I am

Why is there no string interpolation in Scala?

て烟熏妆下的殇ゞ 提交于 2019-11-29 13:18:30
This is not just an idle quip... I wonder if anybody knows if there's an actual design reason why Scala does not support interpolation similar to Groovy and other "syntactically better Javas"? e.g. var str1 = "World"; var str2 = "Hello, ${str1}"; retronym The proposed solution is to omit spaces when using + . "a="+a+", b="+b It has been suggested that a Swiss keyboard layout makes this very natural to type, so the creators of Scala don't feel enough pain to justify complicating the langauge in this direction :) String interpolation is in Scala 2.10. See the SIP . If you're using an earlier

C#: Property overriding by specifying the interface explicitly

泄露秘密 提交于 2019-11-29 11:41:20
问题 While attempting to override the explicit interface implementation of the ICollection<T>.IsReadOnly property from the Collection<T> class, I came across some documents stating that explicit interface member implementations cannot be overridden because they cannot have modifiers such as virtual or abstract . On MSDN they even go as far as specifying how to make an explicit interface member implementation available for inheritance by creating another abstract or virtual member which is called

Is there, or is there ever going to be, a conditional operator in Delphi?

▼魔方 西西 提交于 2019-11-29 10:41:21
问题 I kept my hands off Delphi for too long, I guess; busied myself with Java and PHP a lot over the last couple of years. Now, when I got back to doing a little Delphi job, I realised I really miss the conditional operator which is supported by both Java and PHP. On how many places would you find lines like these in your Delphi programs? var s : string; begin ...<here the string result is manipulated>... if combo.Text='' then s := 'null' else s := QuotedStr(combo.Text); result := result + s; end

Is there a use of free floating block inside a method in Java?

匆匆过客 提交于 2019-11-29 09:19:56
I didn't know methods could have floating blocks like this: class X { public static void main( String [] args ) { { //<--- start int i; } //<-- ends } } I was aware of floating blocks outside methods, but never tried them inside. This could probably be used to define local scope or something. Is there a use for floating blocks inside methods in Java? Is there a use? Yes - to limit the scope of local variables. Is it a good idea? Probably debatable (and likely will be). The "pro" camp will say it never hurts to narrow the scope of variable. The "con" camp will say that, if you use it in a

Should inheritance (of non-interface types) be removed from programming languages?

断了今生、忘了曾经 提交于 2019-11-29 06:40:29
问题 This is quite a controversial topic, and before you say "no", is it really, really needed? I have been programming for about 10 years, and I can't honestly say that I can recall a time where inheritance solved a problem that couldn't be solved another way. On the other hand I can recall many times when I used inheritance, because I felt like I had to or because I though I was clever and ended up paying for it. I can't really see any circumstances where, from an implementation stand point,

How do you force constructor signatures and static methods?

倾然丶 夕夏残阳落幕 提交于 2019-11-29 05:28:58
Is there a way of forcing a (child) class to have constructors with particular signatures or particular static methods in C# or Java? You can't obviously use interfaces for this, and I know that it will have a limited usage. One instance in which I do find it useful is when you want to enforce some design guideline, for example: Exceptions They should all have the four canonical constructors, but there is no way to enforce it. You have to rely on a tool like FxCop (C# case) to catch these. Operators There is no contract that specifies that two classes can be summed (with operator+ in C#) Is

Is Java assert broken?

荒凉一梦 提交于 2019-11-29 05:26:10
问题 While poking around the questions, I recently discovered the assert keyword in Java. At first, I was excited. Something useful I didn't already know! A more efficient way for me to check the validity of input parameters! Yay learning! But then I took a closer look, and my enthusiasm was not so much "tempered" as "snuffed-out completely" by one simple fact: you can turn assertions off.* This sounds like a nightmare. If I'm asserting that I don't want the code to keep going if the input

C++11 feature checking

核能气质少年 提交于 2019-11-29 04:28:40
How do I check for presence of individual C++0x/C++11 language features? I know Clang has a nice system for this. What about GCC, Visual Studio or Boost? I guess one way to do it is to detect the compiler version and relate that to the features introduced in that version. But that is cumbersome. Has someone already done that? mirk boost config comes with a script to check for some but not all C++11 features. It generates a config-file with macros for each feature. Your build-tool may be able to help with this. CMake has the try_compile command which allows you to test whether a code sample