История изменений
Исправление kaldeon, (текущая версия) :
Утиная типизация с проверками компиляции. Чуть подробнее [1]:
Go's interfaces let you use duck typing like you would in a purely dynamic language like Python but still have the compiler catch obvious mistakes like passing an int where an object with a Read method was expected, or like calling the Read method with the wrong number of arguments.
. . .
Languages with methods typically fall into one of two camps: prepare tables for all the method calls statically (as in C++ and Java), or do a method lookup at each call (as in Smalltalk and its many imitators, JavaScript and Python included) and add fancy caching to make that call efficient. Go sits halfway between the two: it has method tables but computes them at run time. I don't know whether Go is the first language to use this technique, but it's certainly not a common one. (I'd be interested to hear about earlier examples; leave a comment below.)
Проблема с дженериками была в том, что интерфейсы уже были очень динамической частью языка и поэтому дженерики, как отдельная часть языка, неизбежно бы съел часть пирога интерфейсов. Эта одна из тех вещей, которую Go избегает всеми силами: использование разных средств для решения одной задачи. В итоге Go сделал нечто уникальное: скрестил интерфейсы с дженериками, сохранив старую форму интерфейсов как норму. To my knowledge, ни один другой язык ещё не делал такого.
Edit: только сейчас узнал, что Роб Пайк уже озвучил эту проблему [2]:
Critics often complained we should just do generics, because they are «easy», and perhaps they can be in some languages, but the existence of interfaces meant that any new form of polymorphism had to take them into account.
[1]: https://research.swtch.com/interfaces
[2]: https://commandcenter.blogspot.com/2024/01/what-we-got-right-what-we-got-wron...
Исправление kaldeon, :
Утиная типизация с проверками компиляции. Чуть подробнее [1]:
Go's interfaces let you use duck typing like you would in a purely dynamic language like Python but still have the compiler catch obvious mistakes like passing an int where an object with a Read method was expected, or like calling the Read method with the wrong number of arguments.
. . .
Languages with methods typically fall into one of two camps: prepare tables for all the method calls statically (as in C++ and Java), or do a method lookup at each call (as in Smalltalk and its many imitators, JavaScript and Python included) and add fancy caching to make that call efficient. Go sits halfway between the two: it has method tables but computes them at run time. I don't know whether Go is the first language to use this technique, but it's certainly not a common one. (I'd be interested to hear about earlier examples; leave a comment below.)
Проблема с дженериками была в том, что интерфейсы уже были очень динамической частью языка и поэтому дженерики, как отдельная часть языка, неизбежно бы съел часть пирога интерфейсов. Эта одна из тех вещей, которую Go избегает всеми силами: использование разных средств для решения одной задачи. В итоге Go сделал нечто уникальное: скрестил интерфейсы с дженериками, сохранив старую форму интерфейсов как норму. To my knowledge, ни один другой язык ещё не делал такого.
Edit: только сейчас узнал, что Rob Pike уже озвучил эту проблему [2]:
Critics often complained we should just do generics, because they are «easy», and perhaps they can be in some languages, but the existence of interfaces meant that any new form of polymorphism had to take them into account.
[1]: https://research.swtch.com/interfaces
[2]: https://commandcenter.blogspot.com/2024/01/what-we-got-right-what-we-got-wron...
Исходная версия kaldeon, :
Утиная типизация с проверками компиляции. Чуть подробнее [1]:
Go's interfaces let you use duck typing like you would in a purely dynamic language like Python but still have the compiler catch obvious mistakes like passing an int where an object with a Read method was expected, or like calling the Read method with the wrong number of arguments.
. . .
Languages with methods typically fall into one of two camps: prepare tables for all the method calls statically (as in C++ and Java), or do a method lookup at each call (as in Smalltalk and its many imitators, JavaScript and Python included) and add fancy caching to make that call efficient. Go sits halfway between the two: it has method tables but computes them at run time. I don't know whether Go is the first language to use this technique, but it's certainly not a common one. (I'd be interested to hear about earlier examples; leave a comment below.)
Проблема с дженериками была в том, что интерфейсы уже были очень динамической частью языка и поэтому дженерики, как отдельная часть языка, неизбежно бы съел часть пирога интерфейсов. Эта одна из тех вещей, которую Go избегает всеми силами: использование разных средств для решения одной задачи. В итоге Go сделал нечто уникальное: скрестил интерфейсы с дженериками, сохранив старую форму интерфейсов как норму. To my knowledge, ни один другой язык ещё не делал такого.