Каковы дефициты системы типов Java/C#?

8000 - порт по умолчанию. Используйте вместо:

php artisan serve --port=8005
6
задан Camilo Díaz Repka 12 December 2010 в 03:08
поделиться

7 ответов

Arrays are broken.

  Object[] foo = new String[1];
  foo[0] = new Integer(4);

Gives you java.lang.ArrayStoreException

You deal with them with caution.

Nullability is another big issue. NullPointerExceptions jump at your face everywhere. You really can't do anything about them except switch language, or use conventions of avoiding them as much as possible (initialize fields properly, etc).

More generally, the Java's/C#'s type systems are not very expressive. The most important thing Haskell can give you is that with its types you can enforce that functions don't have side effects. Having a compile time proof that parts of programs are just expressions that are evaluated makes programs much more reliable, composable, and easier to reason about. (Ignore the fact, that implementations of Haskell give you ways to bypass that).

Compare that to Java, where calling a method can do almost anything!

Also Haskell has pattern matching, which gives you different way of creating programs; you have data on which functions operate, often recursively. In pattern matching you destruct data to see of what kind it is, and behave according to it. e.g. You have a list, which is either empty, or head and tail. If you want to calculate the length, you define a function that says: if list is empty, length = 0, otherwise length = 1 + length(tail).

If you really like to learn more, there's two excellent online sources:

Learn you a Haskell and Real World Haskell

8
ответ дан 8 December 2019 в 12:22
поделиться

I dislike the fact that there is a differentiation between primitive (native) types (int, boolean, double) and their corresponding class-wrappers (Integer, Boolean, Double) in Java.

This is often quite annoying especially when writing generic code. Native types can't be genericized, you must instantiate a wrapper instead. Generics should make your code more abstract and easier reusable, but in Java they bring restrictions with obviously no reasons.

private static <T> T First(T arg[]) {
    return arg[0];
}

public static void main(String[] args) {        
    int x[] = {1, 2, 3};
    Integer y[] = {3, 4, 5};

    First(x); // Wrong
    First(y); // Fine
}

In .NET there are no such problems even though there are separate value and reference types, because they strictly realized "everything is an object".

5
ответ дан 8 December 2019 в 12:22
поделиться

этот вопрос о дженериках показывает недостатки выразительности системы типов java
Дженерики высшего порядка в Java

3
ответ дан 8 December 2019 в 12:22
поделиться

This is minor, but for the current versions of Java and C# declaring objects breaks the DRY principle:

Object foo = new Object; 
Int x = new Int; 
0
ответ дан 8 December 2019 в 12:22
поделиться

(Re: C# specifically.)

I would love tagged unions.

Ditto on first-class objects for classes, methods, properties, etc.

Although I've never used them, Python has type classes that basically are the types that represent classes and how they behave.

Non-nullable reference types so null-checks are not needed. It was originally considered for C# but was discarded. (There is a stack overflow question on this.)

Covariance so I can cast a List to a List.

0
ответ дан 8 December 2019 в 12:22
поделиться

I don't like the fact that classes are not first-class objects, and you can't do fancy things such as having a static method be part of an interface.

2
ответ дан 8 December 2019 в 12:22
поделиться

None of them have meta-programming facilities like say that old darn C++ dog has.

Using "using" duplication and lack of typedef is one example that violates DRY and can even cause user-induced 'aliasing' errors and more. Java 'templates' isn't even worth mentioning..

0
ответ дан 8 December 2019 в 12:22
поделиться