language-features

Compilation error. Using properties with struct

六月ゝ 毕业季﹏ 提交于 2019-11-30 02:48:55
问题 Please explain the following error on struct constructor. If i change struct to class the erros are gone. public struct DealImportRequest { public DealRequestBase DealReq { get; set; } public int ImportRetryCounter { get; set; } public DealImportRequest(DealRequestBase drb) { DealReq = drb; ImportRetryCounter = 0; } } error CS0188: The 'this' object cannot be used before all of its fields are assigned to error CS0843: Backing field for automatically implemented property 'DealImportRequest

python ? (conditional/ternary) operator for assignments [duplicate]

偶尔善良 提交于 2019-11-30 01:06:05
This question already has an answer here: Does Python have a ternary conditional operator? 22 answers C and many other languages have a conditional (aka ternary) operator. This allows you to make very terse choices between two values based on the truth of a condition, which makes expressions, including assignments, very concise. I miss this because I find that my code has lots of conditional assignments that take four lines in Python: if condition: var = something else: var = something_else Whereas in C it'd be: var = condition? something: something_else; Once or twice in a file is fine, but

Why is Self assignable in Delphi?

我只是一个虾纸丫 提交于 2019-11-30 00:54:46
问题 This code in a GUI application compiles and runs: procedure TForm1.Button1Click(Sender: TObject); begin Self := TForm1.Create(Owner); end; (tested with Delphi 6 and 2009) why is Self writable and not read-only? in which situations could this be useful? Edit: is this also possible in Delphi Prism? (I think yes it is, see here) Update: Delphi applications/libraries which make use of Self assignment: python4delphi 回答1: That's not as bad as it could be. I just tested it in Delphi 2009, and it

What is the rationale for not having static constructor in C++?

社会主义新天地 提交于 2019-11-29 23:56:16
What is the rationale for not having static constructor in C++? If it were allowed, we would be initializing all the static members in it, at one place in a very organized way, as: //illegal C++ class sample { public: static int some_integer; static std::vector<std::string> strings; //illegal constructor! static sample() { some_integer = 100; strings.push_back("stack"); strings.push_back("overflow"); } }; In the absense of static constructor, it's very difficult to have static vector, and populate it with values, as shown above. static constructor elegantly solves this problem. We could

Does C# have too many language features?

我的未来我决定 提交于 2019-11-29 22:53:47
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 problems, everyone has many other problems to solve every day than to care about nicer ways to implement

How does your favorite language handle deep recursion? [closed]

好久不见. 提交于 2019-11-29 21:47:22
I recently started learning Python and I was rather surprised to find a 1000 deep recursion limit (by default). If you set it high enough, about 30000, it crashes with a segmentation fault just like C. Although, C seems to go quite a lot higher. (The Python folks are quick to point out that you can always convert recursive functions to iterative ones and that they're always faster. That's 100% true. It's not really what my question is about though.) I tried the same experiment in Perl and somewhere around 10 million recursions it consumed all of my 4 gigs of ram and I used ^C to stop trying.

What's the new way to iterate over a Java Map in Scala 2.8.0?

早过忘川 提交于 2019-11-29 21:24:20
How does scala.collection.JavaConversions supercede the answers given in Stack Overflow question Iterating over Java collections in Scala (it doesn't work because the "jcl" package is gone) and in Iterating over Map with Scala (it doesn't work for me in a complicated test which I'll try to boil down and post here later). The latter is actually a Scala Map question, but I think I need to know both answers in order to iterate over a java.util.Map . In 2.8, you import scala.collection.JavaConversions._ and use as a Scala map. Here's an example (in 2.8.0.RC1): scala> val jmap:java.util.Map[String

What is the purpose of long, double, byte, char in Java?

我们两清 提交于 2019-11-29 19:05:31
So I'm learning java, and I have a question. It seems that the types int , boolean and string will be good for just about everything I'll ever need in terms of variables, except perhaps float could be used when decimal numbers are needed in a number. My question is, are the other types such as long , double , byte , char etc ever used in normal, everyday programming? What are some practical things these could be used for? What do they exist for? With the possible exception of "short", which arguably is a bit of a waste of space-- sometimes literally, they're all horses for courses: Use an int

Samples of Scala and Java code where Scala code looks simpler/has fewer lines?

爱⌒轻易说出口 提交于 2019-11-29 19:03:40
I need some code samples (and I also really curious about them) of Scala and Java code which show that Scala code is more simple and concise then code written in Java (of course both samples should solve the same problem). If there is only Scala sample with comment like "this is abstract factory in Scala, in Java it will look much more cumbersome" then this is also acceptable. Thanks! I like most of all accepted and this answers Esko Luontola Let's improve stacker's example and use Scala's case classes : case class Person(firstName: String, lastName: String) The above Scala class contains all

How can I get the callee in PHP? [duplicate]

陌路散爱 提交于 2019-11-29 15:20:52
Possible Duplicate: Caller function in PHP 5? I would like to know from where a global function or public method is being called. I guess I could do it by inspecting debug_backtrace but I'd rather use a lighterweight mechanism if one exists. Any suggestions? For example something like so, if you imagine the get_callee() function and constant existing: function doSomething() { if(get_callee() == 'PHP_GLOBAL') { throw new IllegalAccessException(); } ... } alexn Edit: Sorry, saw your note about debug_backtrace() now. Kinda ugly but hey, if you need to do this something is wrong. The magic is in