Tag Info

New answers tagged

3

You're right that data Foo (or even Foo) and Bar can't be used interchangeably in Haskell code, but one might argue that type definitions, such as data List a = Nil | Cons a (List a) can be transformed into an "equation" of the form List(a) = 1 + a * List(a). And you can then start playing with it as if it were an algebraic expression: the equation can be ...


1

Foo is a type, Bar is a value. It doesn't make sense to speak of exchanging them. Rather, the equality sign expresses that type Foo consists of precisely those values on the right; no more and no less.


0

C: var = ((a = foo()), b = bar(), baz(), a + b); Using the comma operator to perform multiple operations, but return the right most expression. Can use used in macros for eg, growing an array and assigning a value (and many other things of course). #define ARRAY_DECLARE(arr) \ int _##arr##_count = ...


1

Yes you can [re]write programs without break statements (or returns from the middle of loops, which do the same thing). But you may have to introduce additional variables and/or code duplication both of which typically make the program harder to understand. Pascal (the programming language) was very bad especially for beginner programmers for that reason. ...


-1

Before Java there was C, C++ and Pascal. Enumerations in C and C++ could have wildly different values - they did not need to be contiguous integers. This had the advantage that you could define an enum for things like Windows message codes, which were a sparse set of non-contiguous integers. (Borland) Pascal took the other approach, where all enumerations ...


9

In Java, the enum is a reference type (don't let that little 'e' fool you). You can do neat things with it like define methods. A classic example of that is the Operation enum being defined as: public enum Operation { PLUS { double eval(double x, double y) { return x + y; } }, MINUS { double eval(double x, double y) { return x - y; } }, TIMES { ...


1

enums are replaced with their constant values in the executable. they can not be traversed at runtime. in C enum are part of the source code and the compiler replaces the enum with the constant int. // C source - enum gets replaced with constant enum _tenum { A, B, C}; _tenum ft; ft = B; // assembler enum is gone. only constant value 1 remains ...


1

Technically speaking, there is a way to perform a next operation in both languages, though it varies between Java and C#. C# In C#, enumerations are number types at their core. You can simply perform addition with integers: var day = DayOfWeek.Sunday; foreach(var n in Enumerable.Range(0, 7)) Console.WriteLine("Day of week: {0}", day + n); note: the ...


6

Why isn't there a next operation on enums? It is difficult to generalize. It is an decision made by each programming language designer / team. But note that some programming languages do provide a "next" operation for enumerated types. In Pascal, the succ function returns the next value of an enumerated type, and the pred function returns the ...


2

It is because of the nature of enums (enum in Java), (enum in C#). They are just fixed constants in the language, holding essential data (sometimes just their own names or just identity), not a kind of list. Therefore if you need this kind of logic (which might be applicable to many cases), then you actually have to create the logic. Apart of being some ...


-5

Speaking for Java, what you are actually looking for is Enumeration (which is more like iterator) which has the nextElement support. enum is a data type which allows variable to have a set of predefined values.


2

I would argue that you have missed the addition of some of the necessary features because they weren't being highlighted as for unit testing. For example, unit testing in C# is mainly driven by using attributes. The Custom Attributes feature provides a rich extension mechanism that allows frameworks like NUnit to iterate and compete, with things like ...


6

A lot of languages have support for testing. C's asserts are tests that the program can fail. That's where most languages stop, but Eiffel and more recently Ada 2012 have preinvariants (things the arguments to a function must pass) and postinvariants (things the output of a function must pass), with Ada offering the ability to reference the initial arguments ...


2

Some proponents of strongly typed functional languages would argue that these language features reduce or eliminate the need for unit tests. Two, imho, good example of this for this is from F# for Fun and Profit here and here Personally, I am still believe in the value of unit tests, but there are some valid points. E.g. if an illegal state is ...


13

Because testing, and particularly test-driven development, is a deeply counter-intuitive phenomenon. Almost every programmer begins their career believing they are much better at managing complexity than they actually are. The fact that even the greatest programmer cannot write large and complex programs without severe errors unless they use lots of ...


16

There's lots of reasons. Eric Lippert has stated many times that the reason feature X isn't in C# is because it's just not in their budget. Language designers don't have an infinite amount of time nor money to implement things, and each new feature has maintenance costs associated with it. Keeping the language as small as possible isn't just easier for the ...


32

As with many things, unit testing is best supported at the library level, not the language level. In particular, C# has numerous Unit Testing libraries available, as well as things that are native to the .NET Framework like Microsoft.VisualStudio.TestTools.UnitTesting. Each Unit Testing library has a somewhat different testing philosophy and syntax. All ...



Top 50 recent answers are included