Thursday 15 July 2010

.net - Why doesn't C# allow an else clause on loops? -


I have decided to learn some Python (IronPathon) syntax today. In doing so, I was impressed with the construction, which allows its loops

Python supports a else section on its loop basically a loop But a else says, "If this loop ends normally, enter this section".

Allow me to use C #.

This code:

  some = some calTauset (); BoolCompatable = false; Foreach (widget widget in widgets) {COMPATEBLE = WIDGETS. IOS CompatibilityWith some (some); If (compactable) break! } If (Compactable) Compatable Somatings Add (some);   

This code may be (not valid C #):

  Something = SomeCallToSetThisUp (); Foreach (Widget Widgets in Widgets) {if (Widget! ICA CompatibilityWith some (some)); break; } And include compliant. Add (some);   

It's never seen, it hit me as cool. And once you learn it, it seems that whatever code I have seen is worth reading.

Not universally necessary (sometimes you want to influence every item in the list), I think it would be useful.

So, my question is: Why is not it in C #?

Why do I have some ideas:

  • break can make debugging difficult, so designers do not want to encourage it
  • Shiny can not make everything in language (limited scope).

    But this is just the guess I am asking for a real legal reason .

    The general answer is because anyone asked for it or to develop and maintain profit Asked the cost.

    From Eric Lepert's blog:

    I have several times before, the two most important points in Eric's posts on Eric Gunnison's C # design process: (1 ) This is not a subtractive process; We do not start with C ++ or Java or Haskell and then decide whether to leave some of them or not. And (2) just not enough to be a good feature, the features should be so compelling that they are worth the cost of huge dollars of design, implementation, testing, documentation and shipping costs. They have to be worth the price of engaging the language and making it more difficult to design other features in the future.

    After finishing the smallest designs of the last minute of different parts of C # 3.0, we can think about the facility that could potentially go to future versions of C #. We spent many hours, many hours trying to "bucket" through each feature in that list. Each feature has been put into a unique bucket. The bucket was labeled:

    Pri 1: Must be in the next version

    Pri 2: Should be in the next version

    Pri3: Good In the next version

    Pri 4: Before we can do this, the need for intensive study for many years

    Pri 5: Bad thoughts

    Obviously we Immediately stopped thinking, in the context of the next edition, fourteen and favs, we increased the cost of facilities in the first three buckets, compared to their comparisons This was done in terms of design, implementation, testing and documentation of resources available by us. The cost was much higher than the available resources, so we cut everything in bucket 2 and 3, and in about half of the bucket, 1. come out that some of them will be "necessary", in fact "stare".

    This bilting process will help in understanding when I will talk about some of the suggested features in that long forum. Many of the suggested features were perfectly good, but fell into the bucket. They did not make a 100 point deficit, they were not just compelling enough.

    In addition, if this feature is easily understood by existing / new developers, then you will need weight to loop on IMHO Other It is not very readable, especially when 'Execute this block if the last one has been fixed' is the keyword, then finally

    what is more, I think Is that enumerable Any / Enumerable.All methods are much better in this scenario.

No comments:

Post a Comment