Disadvantage of Go1 No Generic For Now
That make user coding repeat code many times, even for basic type such as int float boolIt is not easy , even to make a generic min function.
using interface will always check type casting.and for []interface{} in generic function, u can't do cast
2 Incomplete Type in Basic LibTake math lib as an example, math.Max math.Min are only for float64 ,you have do stupid conversion for other type.
3 No Default Value for struct.Consider multilayer struct. A {B {C {D {E {F} } } }to init A to a default value will be complicated.And how about A[] sliceAnd what if D E F are from third party lib ?You have to dig into 3rd party code just for its default value.For It may have none zero default value.
4 Can not Cycle import.package A B can not import each other at the same time.While other language can.It seems not a big deal just put the the common thing in a new packageBut when the package and project grow bigger, it just easy to say.This change will affect all caller.
5 Inconsistent type conversionbool type are normal type just like int and float ,but u can't do below. while other type can cast to othersint(bool) bool(int)
6 No multi casting expressionfunc foo() (int16, int8)var i,j int32 = (int32,int32)(foo())Since go can't do this, why go provide multi return value.
7 No Ternary Expressionhardly find a language without it except go
8 No Negative Index for sliceall other script language support a[-1] as a[len(a)-1]
When programing in gowe have to do repeated type casting many times, due to the above.write long code for Ternary ,int(bool) a[-1] etc
init big struct with default value.Which make Go not an Elegant and simple language.Once I thought go was a simple language,but in fact we write more code.All above are proposal for many times.And it is 6 years(or more).These basic functions are still not added. some of that should be add in version 1.0I belive most above could make go simpler,someone know a little programing could know how to use it.however someone still fear it make go complicate like c++
thank u very much. I know they all have work around. and I also write some util my own.I just wish go to make it more simpler, wish the code could be clean and short .Right now go let programer do repeat and Mechanical workthe top 3 are bothering me most
[1],[2] let me do many type cast all the time.[3] let me have to do initialize default for each struct.right now I am solving [3] like this.type F struct {x int32}var FDefault = F{x:1}type E struct {f F}var EDefault = E{f: FDefault}type D struct {e E}var DDefault = D{e: EDefault}
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
One minor point is that you cannot fake the ternary operator with a function. In the function call the two alternates are evaluated before the call so this breaks ... everything else with side effects such as function calls.
Am 14.01.2017 um 12:27 schrieb parais...@gmail.com:
> Some time ago I collected a number of alternatives to using generics - see: https://appliedgo.net/generics
None of these alternatives really solve any real problem generics would solve. Generics are types, just like first class functions. Lamenting on the lack on generics is useless as well, Go will never have generics because of forward compatibility.But let's not pretend than there is an alternative to generics "people can't see" within Go. Go just wasn't built for code re-use in mind or writing abstractions at all due to the lack of polymorphism in the language. So people have to write specialized code when it comes to writing logic involving containers, that's the only truth there is.
> If you have a particular problem and you think, "I do need generics to implement that!", then you might become blind for other solutions.
It's not being blind to another solution, every other solution has drawbacks generics don't have. Code generation involve writing pre-processors and maintaining manifests, opting out of Go type system with interface{} everywhere is obviously problematic. That's not solving what generics are here for in languages such as Java C# or Haskell. Basically you are asking developers to pay a price the compiler doesn't want to pay. Let's not patronize people who see the obvious flaw in that logic.Again while it is useless to complain, people are complaining for a good reason, it can be difficult to understand what led to the absence of generics at first place in Go design. People coming from C,Python,Javascript and Ruby might not care, people coming from Java, C# or Haskell will have harder time working around the lack of generics in Go because they are used to that feature to solve their problems.To the latter I'd say that if Go feels tedious for a task then use something else, really. Go wasn't designed to please people who like expressive static type systems. There are many alternatives such as D, Ocaml, ...
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/AcUcEIOUfh8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.