language-features

Problem with loop optimization or closure of lambda?

一曲冷凌霜 提交于 2019-11-29 02:57:44
问题 In the following method I'm sending an enumeration of actions and want an array of ICommands back that call Action<object> that wrap those actions (needed for the relayCommand). The problem is that if I do this inside the for each (or even a for loop) I get commands that always execute the first action passed in the parameters. public static ICommand[] CreateCommands(IEnumerable<Action> actions) { List<ICommand> commands = new List<ICommand>(); Action[] actionArray = actions.ToArray(); //

What are the benefits of such flexible “self-identifiers” in F#?

别来无恙 提交于 2019-11-28 23:11:20
While I understand self-identifiers in F#, I am puzzled as to the benefits of such flexibility. Why does F# not just support this.Blah as C# does and be done with it? I'm guessing some people use it to improve readability, but even that seems a stretch. So, what are the uses/benefits of this language feature? For the un-initiated, below is an example that defines a type-wide self identifier "self" and a method scoped identifier "this". The example is taken from the MSDN article linked above. type MyClass2(dataIn) as self = let data = dataIn do self.PrintMessage() member this.PrintMessage() =

What is the difference between VB and VBScript

亡梦爱人 提交于 2019-11-28 22:28:52
What is the difference between VB and VBScript? VB is a full-fledged programming language which can be used to create compiled applications, while VBScript is a sub-set of VB and is a scripting language that can be used to run a set of commands, similar to an old-school DOS batch file. Generally, a scripting language can not be used to create a full-fledged binary application and it can not be compiled down to a executable binary file. Shog9 VBScript is a variety of VB, just as VB6 , VBA , and VB.NET are. They're all different, some of them dramatically so . This is a very old question, but

Java Private Field Visibility

主宰稳场 提交于 2019-11-28 20:37:18
So I was making a class the other day and used Eclipse's method to create the equals method when I realized that it generated the following working code: class Test { private int privateInt; [...] public boolean equals(Object obj) { [...] Test t = (Test) obj; if ( t.privateInt == privateInt ) { [...] } } t.privateInt..???? It's suppose to be private! So I guess there is one more field visibility other than private, protected, package protected and public. So what is happening here? How is this called? Where would somebody use this? Doesn't this break encapsulation? What if the class didn't

Name this python/ruby language construct (using array values to satisfy function parameters)

会有一股神秘感。 提交于 2019-11-28 18:47:19
What is this language construct called? In Python I can say: def a(b,c): return b+c a(*[4,5]) and get 9. Likewise in Ruby: def a(b,c) b+c end a(*[4,5]) What is this called, when one passes a single array to a function which otherwise requires multiple arguments? What is the name of the * operator? What other languages support this cool feature? The Python docs call this Unpacking Argument Lists . It's a pretty handy feature. In Python, you can also use a double asterisk (**) to unpack a dictionary (hash) into keyword arguments. They also work in reverse. I can define a function like this: def

Are there equivalents to Ruby's method_missing in other languages?

孤者浪人 提交于 2019-11-28 18:46:05
In Ruby, objects have a handy method called method_missing which allows one to handle method calls for methods that have not even been (explicitly) defined: Invoked by Ruby when obj is sent a message it cannot handle. symbol is the symbol for the method called, and args are any arguments that were passed to it. By default, the interpreter raises an error when this method is called. However, it is possible to override the method to provide more dynamic behavior. The example below creates a class Roman, which responds to methods with names consisting of roman numerals, returning the

Does C# have too many language features?

怎甘沉沦 提交于 2019-11-28 18:36:54
问题 This is a discussion that pops a from time to time in our team. While a few quickly learned C# 3.0 features, other stick with classical techniques. Some never use Linq, think that lambda expressions are confusing and yield is "scary". Sometimes they can hardly understand code that is written by people using all the new features. We can just say that they do not master the language and should learn it. But how hard should it be to learn a modern programming language? Everyone can solve the

Why does HTML5 not include a way of loading local HTML into the document?

梦想与她 提交于 2019-11-28 18:15:05
I've thinking about this a lot lately. Why does HTML5 not really let you load HTML into your document to break up your HTML files? It has support for nearly every other asset (images, videos, audio). Yes we have iframes , embeds , and objects but they are sandboxed and don't follow the flow of the rest of the document. I was thinking of something like: <h2>My wonderful application</h2> <include src = "leftPane.html" type = "text/html" /> <include src = "main.html" type = "text/html" /> <include src = "footer.html" type = "text/html" /> I would love for someone to explain this to me. In nearly

Python type() or __class__, == or is

北城余情 提交于 2019-11-28 17:25:21
I want to test whether an object is an instance of a class, and only this class (no subclasses). I could do it either with: obj.__class__ == Foo obj.__class__ is Foo type(obj) == Foo type(obj) is Foo Are there reasons to choose one over another? (performance differences, pitfalls, etc) In other words: a) is there any practical difference between using __class__ and type(x) ? b) are class objects always safe for comparison using is ? Update: Thanks all for the feedback. I'm still puzzled by whether or not class objects are singletons, my common sense says they are, but it's been really hard to

Can someone demystify the yield keyword?

不想你离开。 提交于 2019-11-28 17:14:57
I have seen the yield keyword being used quite a lot on Stack Overflow and blogs. I don't use LINQ . Can someone explain the yield keyword? I know that similar questions exist. But none really explain what is its use in plain simple language. By far the best explanation of this (that I've seen) is Jon Skeet's book - and that chapter is free! Chapter 6, C# in Depth . There is nothing I can add here that isn't covered. Then buy the book; you will be a better C# programmer for it. Q: Why didn't I write a longer answer here (paraphrased from comments); simple. As Eric Lippert observes ( here ),