Changes you want for Go 2.0

agolangf · · 450 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<pre><code>We need your help. Please tell us how Go is working for you, and more importantly not working for you </code></pre> <p>So it seems that they wanna hear the community, let&#39;s make it! Starting from now, let&#39;s put here what features would you like for the new version of Go. I want every Gopher that reads this to post below a list of improvements with their personal preferences. This way they&#39;ll know what people prefer and what should be changed.</p> <p><strong>The most common changes will be pinned here!!</strong></p> <p>EDIT: RSC&#39;s post should be takken in consideration.</p> <p><strong>Pinned posts:</strong></p> <p><a href="https://www.reddit.com/r/golang/comments/6n4rqj/changes_you_want_for_go_20/dk7yn8t/">https://www.reddit.com/r/golang/comments/6n4rqj/changes_you_want_for_go_20/dk7yn8t/</a></p> <hr/>**评论:**<br/><br/>rsc: <pre><p>I&#39;m very sorry, but it seems you missed the main point of my talk / <a href="https://blog.golang.org/toward-go2">blog post</a>. We can&#39;t start with a feature list. We need to start with the problems Go 2 needs to solve. See the blog post for more details.</p></pre>slowratatoskr: <pre><p>obviously generics</p> <p>edit:</p> <p>lol why the downvotes? i mean, whats the point of Go2 if generics will not be included. </p></pre>gempir: <pre><p>Generics is an answer you need to bring the question </p></pre>to_be_deleted_soon: <pre><p>How can I write code that is easily applicable to many types?</p></pre>to_be_deleted_soon: <pre><p>How can we increase type safety?</p></pre>to_be_deleted_soon: <pre><p>How do I remove the vector of error where I have to manually change 10 methods when I want to make a change to all my type-specific implementations, that I copy-pasted to begin with but are beginning to become cumbersome to edit?</p></pre>to_be_deleted_soon: <pre><p>Why does the language contain generics to begin with (map)? Should we remove map?</p></pre>skztr: <pre><p>That&#39;s what I don&#39;t like: internals being treated specially. Internals get to be treated genetically, internals get to iterate. I don&#39;t even care about these issues as &#34;I should get to do that, too!”, I just want consistent syntax, so that I don&#39;t need to ask, separately: ”how do I do this with a built-in type?&#34; Or &#34;how do I do this when I don&#39;t have a built-in type?&#34;</p></pre>saturn_vk: <pre><p>How do I create a set as a library, so that arbitrary people can use it?</p></pre>4ad: <pre><p>You are not bringing any question to a table, you are proposing a solution to an unknown problem.</p></pre>Tyler11223344: <pre><p>I think you replied to the wrong comment?</p></pre>4ad: <pre><p>No, I did not.</p></pre>Tyler11223344: <pre><p>In what way was his comment not a question/problem?</p></pre>to_be_deleted_soon: <pre><p>Why has other modern languages had this feature for almost a decade? Perhaps this is a pointer as to the fact that it could be an appreciated feature? </p></pre>to_be_deleted_soon: <pre><p>How can we reduce code duplication and increase robustness and ease of testing? </p></pre>chuck7000: <pre><p>Nope</p></pre>kardianos: <pre><p>I think Russ was asking for:</p> <p><code>2. Identify and explain a problem.</code></p> <p>As in, &#34;I was building a large system for running economic simulations and I found that the various and I found it difficult to share code between X and Y models. Here are some examples of what I was trying to do and why it was time consuming or error prone.&#34;</p></pre>Starz0r: <pre><p>Writing Dynamic Libraries (DLL/dylib) and Shared Objects (so), should be a first class feature in Go 2. Would allow me to drop C almost entirely.</p></pre>Kochie_94: <pre><p>Is there absolutely no way of doing this right now with go?</p></pre>Starz0r: <pre><p>There is the Plugin build mode, but it only works on Linux, and you can only load it in other Go code.</p> <p>There is also a c-shared buildmode, but it&#39;s very hacky, and requires Clang or GCC, and also doesn&#39;t work on Windows.</p> <p>So no, there is no real easy or native way to do it with Go right now.</p></pre>Kochie_94: <pre><p>Okay interesting, I&#39;ve just started my golang journey. Looks like I&#39;m in for some adventurous times.</p></pre>allowthere: <pre><p>One thing I want to point out to everyone (whether here or on HN) is that Go isn&#39;t C, it&#39;s not Rust, and it&#39;s not C++,Java,C#,Haskell, OCaml, or Javascript.</p> <p>Go is <em>Go</em>. It has it&#39;s own culture and it&#39;s own way of doing things. By adding enums, Genrics, Functional paradigms, mandatory nil checking, and other features of Rust, you won&#39;t get a better Go. You get a worse Rust.</p> <p>Yes, each could be nice on their own. Each could serve a purpose. I wouldn&#39;t mind generics, but, at the end of the day, if I wanted to program Rust, I&#39;d use Rust[1].</p> <p>[1]. And I do, for some hobby projects. It&#39;s not a bad language, and not that hard to learn if you just allocate on heap everywhere (no lifetimes - Yay!). And Rusts safety does have its uses (Yes, I&#39;d be quite angry if my browser panicked because of a nil pointer). But many uses don&#39;t require that crazy level of stability (if my web-app goes down, log it and have systemd restart it), and <em>that&#39;s</em> where Go shines.</p></pre>sin2pifx: <pre><blockquote> <p>You get a worse Rust.</p> </blockquote> <p>Why? They aren&#39;t features of Rust. Enums, generics and nil checking exist in e.g. TypeScript and Kotlin, and the first two in C++ and Java. And in those languages, you can program without using them.</p> <p>I know many people don&#39;t like to have multiple ways to write the same. For generics, that&#39;s not an issue. And interface{} stays useful for cases where you want different types. Nil checking idem.</p></pre>allowthere: <pre><p>I&#39;m not picking on Rust personally, it just happens to be seen right now as an &#34;anti-Go&#34; - compiled (unlike Java/C#), with a decent dependency system (unlike C++), came out around the same time, and (due to misunderstandings) is viewed as a &#34;competitor&#34;. </p> <p>But in reality, every language has its culture, and just as one wouldn&#39;t demand OOP from Rust, one shouldn&#39;t demand non-Go idioms in Go. It&#39;s not that they&#39;re <em>bad</em>, they just don&#39;t fit the language.</p> <p>PS. (Not addressed to you personally, but more to the &#34;let&#39;s ban Go&#34; crowd on HN)</p> <p>What I don&#39;t understand is the frequent &#34;why can&#39;t Go be more modern&#34; complaints. Go happens to be one of the more insular communities I found, which practices practically no evangelism. The culture seems to be one of &#34;You like the language, use it. You don&#39;t, fine, use something else&#34;. </p> <p>It&#39;s not a &#34;corporate language&#34; like Java or C# (where the more people use the language, the more money/visibility mother-ship makes). It seems right now that Dart is much more of &#34;Google&#39;s language&#34; than Go. </p> <p>What happened was that a few engineers in Google made a language which would fit their needs, and open sourced it. They never <em>promised</em> generics, they never <em>promised</em> enums, they explicitly said that the language was meant for <em>their</em> use-cases. Don&#39;t like it? Doesn&#39;t fit your use-case? Can&#39;t accept their compromises? No one is forcing the language on anyone. </p> <p>But guess what, people like it and use it. </p></pre>sin2pifx: <pre><p>Fine, but these features can make life easier. I like go&#39;s simplicity. It a sort of anti-C++. But I just don&#39;t think adding two or three features will make Go a worse Rust.</p></pre>dobegor: <pre><p>More low-level stuff in runtime and unsafe. I.e. bit backing.</p> <p>The problem it would solve: it would allow creation of more low-level libraries for Go easily. I.e. implementing some old network protocol requires messing with bits. Bit backing would ease the process.</p> <p>Generics. Problem: various places - containers, linked lists, more accurate type (de-)serialization.</p> <p>DLLs (plugins). Seriously, c-shared build mode only works on Linux and Mac. Problem to solve: get rid of C/C++ for more use cases. Easier to create graphics applications.</p> <p>Better error handling. I don&#39;t think that Go needs and std GUI library, at least now.</p></pre>ops-man: <pre><p>A GUI library would be great. </p></pre>sin2pifx: <pre><p>A GUI library is an answer you need to bring the question</p> <p>/s</p></pre>ops-man: <pre><p>Can Go bring its own GUI library to 2.0 without breaking existing code? </p></pre>hooluupog: <pre><p>Having a modern GUI framework to write cross-platform apps for android and ios(web and desktop,etc). I can do this in JavaScript nowadays but I prefer to do that in Go if possible.IMO,AOT compiled, GC optimized for latency and lower memory footprint make Go a good language for writing apps and even games.</p></pre>sin2pifx: <pre><p>Sure. I was paraphrasing criticism on the request for generics.</p></pre>Undreren: <pre><p>I sorely miss this. I don&#39;t want to use Qt or Gtk or whatnot to make desktop UI&#39;s. It&#39;s not very &#34;batteries included&#34;, IMO.</p></pre>yami_odymel: <pre><p>Agree with this. It&#39;s really hard to see a GUI Application which is written in Go</p></pre>pinpinbo: <pre><p>Per RSC requests, here are most of real problems that my team had/have:</p> <ol> <li><p>There is a need for thread-safe collection data structure. <code>sync.Map</code> is a step in the right direction, what about <code>sync.Slice</code>?</p></li> <li><p>There is a need for generic collection types. Just the other day we needed a generic typed Bloom Filter and Deque. I care less about true generics, but not having generic containers is a real problem.</p></li> <li><p>Panic on close channel trips a lot of people. We are currently resorting in closing channel and assigning it to nil to avoid panics. But that&#39;s a hack. Maybe Go 2 can do away with this panic behavior.</p></li> <li><p>The other day, <code>github.com/Sirupsen/logrus</code> library changed its name to <code>github.com/sirupsen/logrus</code>. That caused a lot of chaos in the community. It would be nice to have import alias to avoid this problem in the future.</p></li> <li><p>How can we resolve vendor dependencies of our vendored libraries? Example: We vendored <code>github.com/aaa/bbb</code>. That thing vendored <code>github.com/zzz/yyy</code>. But we also use older version of <code>github.com/zzz/yyy</code>. Which <code>zzz/yyy</code> does Go pick? Perhaps vendoring can support tags/branches so we can pin-point the exact dependency. Example: <code>github.com/zzz/yyy:v1.3.1</code></p></li> <li><p>We are copy and pasting same functions for <code>int</code>, <code>int64</code>, <code>float32</code>, <code>float64</code>. If generics is never going to happen, can we get a <code>Numeric</code> interface?</p></li> </ol></pre>shark1337: <pre><p>Gonna pin it!</p></pre>metamatic: <pre><p>Re: 4, it&#39;d also be nice to have an adequate core logging library so that people didn&#39;t all have to import their own logging libraries.</p> <p>I wouldn&#39;t mind not getting full generics as long as we got parametric polymorphism. At least then we could write collection classes that worked with multiple types with the same methods.</p></pre>elagergren: <pre><blockquote> <p>generic typed Bloom Filter</p> </blockquote> <p>Curious about this one? What types would need to go in it other than string/[]byte? Integers?</p></pre>mit53: <pre><p>integers or simple structs, basically any type that can be a map key</p></pre>Kraigius: <pre><p>Go needs a good dependency manager to be part of the standard toolset.</p> <p><em>cross fingers for dep</em></p></pre>myselfNobody: <pre><p>+1</p></pre>whistlin3: <pre><p>Generics :)</p></pre>NOLAnuffsaid: <pre><p>Yes!!!!!!!!!!!!!!!!! omg Yeeeesssss</p></pre>slowratatoskr: <pre><p>yup, so that we dont have to use <code>interface{}</code></p></pre>shark1337: <pre><p>I&#39;ll start with the following:</p> <ol> <li>Better vendoring system. No more rules, just let me import my package like a node module.</li> <li>Mobile support, one great thing that Go is missing..</li> <li>More lower level features that doesn&#39;t require c binding.</li> <li>Faster JSON parser.</li> <li>GUI Standard Lib!</li> <li>Performance much closer to c/c++</li> </ol></pre>ask: <pre><p>Which of those require language changes?</p></pre>skztr: <pre><p>A better vendoring system would probably &#34;look like&#34; the current language, but definitely wouldn&#39;t be &#34;the same thing&#34;. Ideally, the GOPATH variable shouldn&#39;t be a thing (except as an override for a sane, project-specific, default), for example. That&#39;s a different that, while it would arguably not be a &#34;language change&#34;, would definitely involve a major version bump.</p> <p>I current do all my go builds within docker containers. That&#39;s fine, I suppose. But it&#39;s stupid. It&#39;s a work-around. I shouldn&#39;t need to mock an entire Linux environment just for a modest amount of build sanity. I know that system-wide libraries are a cruft inherited from go being &#34;c, but, you know, not as stupid&#34;, but they obviously hated that aspect of c when they decided to make it use static linking by default. The idea that libraries aren&#39;t entirely project-specific without jumping through hoops is just absurd. If you want a system-wide (or user-wide) cache, that&#39;s fine. That&#39;s what literally every other modern vendoring system already does.</p></pre>mixedCase_: <pre><ul> <li><p>Generics.</p></li> <li><p>Union types (with pattern matching). Also called algebraic data types and what Rust calls &#34;enums&#34;.</p></li> </ul></pre>diegobernardes: <pre><p>This are my dream, would make Go just, perfect. Some kind of immutable would be nice too, it can help eliminate data races and help constructors (referential integrity). </p></pre>elagergren: <pre><p>Among many other things, one thing not mentioned here that I&#39;d like is better constants (a la constexpr) or the ability to mark types as read only, even if they have to be instantiated at runtime.</p></pre>metamatic: <pre><p>Honestly, I&#39;d like to see all variables and method arguments be immutable by default, with some sort of annotation to make them mutable.</p> <p>But I know that&#39;ll never fly with the Go dev team, so I&#39;m not even gonna propose it.</p></pre>dlsniper: <pre><p>This is a terrible, out of context, thread. </p> <p>Russ was very clear in his talk, the community has a voice, but the voice has to be coherent, it has to show why those changes are needed, what are the use cases, pain points they currently present. </p> <p>Some of the changes will be accepted, others won&#39;t. Some will have to wait a while until a clear case made for the request.</p> <p>Some of the changes will be language changes, some will be tooling (either existing or new tooling). </p> <p>Go 2.0 will not happen any time soon. It will be a gradual process, with the desire to keep the compatibility with the current code as much as possible. When that won&#39;t be possible anymore or when those changes will bw in a stable state, maybe a Go 2.0 release will be cut.</p> <p>The changes won&#39;t also be too many, just a few of them, important ones, for which clear cases are made. </p> <p>Currently this thread and the replies to it are so far off it shows the disconnect between simple users and those that actually can present a case for a problem and have the Go team recognize it as an issue. </p> <p>Please wait for rhe video of the talk before you jumping in head first, without putting any thoughts into your requests and why you need them. The more details, clearly described, the better.</p></pre>DeedleFake: <pre><p>Generics. Duh. I am certainly worried about the complexity that badly done generics could add, but they are absolutely necessary for any kind of decent abstraction that&#39;s tied more to functionality than data format. Interfaces do this to some extent, but they&#39;re too limited for a lot of uses, and a lot of their functionality is implemented at runtime, which has some, minor though they may be most of the time, performance implications. Personally, I&#39;d kind of like something that&#39;s used similarly to Haskell&#39;s type classes, where you could essentially declare limitations of accepted types based on functionality. So, for example:</p> <pre><code>generic Addable(a) { oper +(a) a | func Add(a) a } func sum(a ...Addable) { // Do something. I&#39;m not quite sure how you&#39;d be able to pick if it&#39;s using + or // Add(). Might need some kind of function overloading. } </code></pre> <p>Also, I&#39;d really like a revamp of channels. A lot of the things I want, such as infinite buffers and broadcast channels, could also be done through generics potentially, but, either way, I&#39;d also like a cleaner way of doing M:N channel systems, instead of just the 1:1 systems that channels are primarily designed for now. In particular, I&#39;d like a cleaner way to signal multiple producers to stop sending, although that was partially fixed by the addition of the <code>context</code> package.</p></pre>skztr: <pre><p>Just to throw a wild one out there (that I don&#39;t really think is a good idea):</p> <p>The ability to mark return values as &#34;important&#34;, ie: can never be discarded without being assigned to a variable (and based on other go semantics, implicitly the requirement that the variable be used for something). The ability to easily discard the error status of a function without checking it is a bug, not a feature, of the language. I, personally, think &#34;exceptions&#34; are the only sane way of handling errors: ie, do something which says you either need to deal with it, or give it to somebody else who will deal with it, and if that doesn&#39;t happen your program dies because the state of it can no-longer be trusted. But mixing &#34;code that uses exceptions&#34; with &#34;code that doesn&#39;t use exceptions&#34; is always lethal. &#34;important&#34; parameters would give us a path towards sanity.</p> <p>(if you want to allow people to &#34;ignore&#34; errors, make a <code>Must*()</code> variant, that panics in the event of an error)</p> <p>To be less exception-centric: some things require cleanup code (eg, <code>.Close()</code>) to be called on them to prevent, for example, dangling channels. These are also important, and should never be discarded, but it&#39;s currently perfectly legal to do so.</p></pre>ksion: <pre><p>If you&#39;re looking for existing examples of the &#34;important&#34; return value, the <code>#[must_use]</code> annotation on the <code>Result</code> type in Rust is basically this.</p></pre>skztr: <pre><p>Thanks! I didn&#39;t know about this</p></pre>Saethgokk: <pre><ul> <li>Standard official debugger. (not delve or gdb);</li> <li>More low level features;</li> </ul> <p>I&#39;m sick of this :</p> <pre><code>*(*type)(unsafe.Pointer(uintptr(ptr) + uintptr(offset))) madness. </code></pre> <ul> <li>Good well written standard documentation for the Go assembly;</li> <li>Generics;</li> </ul></pre>fakeNAcsgoPlayer: <pre><p>How about eliminating empty interface penalty. Reflection costs to almost none. </p> <p>Maybe improve the C FFI a lot faster. Not everything is go out there when it comes to performance. </p></pre>tmornini: <pre><blockquote> <p>We need to start with the problems Go 2 needs to solve</p> </blockquote> <p>I&#39;d like to avoid the need to create getters and setters, avoiding a <strong>ton</strong> of boilerplate.</p> <p>Of course, without getters and setters, I cannot define an interface to create polymorphic functions.</p> <p>A solution would be a type that allows the definition of exported fields and types that would allow any structure with said exported fields to be received and/or returned by a function.</p></pre>metamatic: <pre><p>Getters and setters are also where I find the lack of parametric polymorphism <em>really</em> annoying. I end up with <code>SetFromInt</code>, <code>SetFromString</code> etc.</p></pre>forfunc: <pre><p>I&#39;m writing distributed systems in Go and often find the need for immutable data structures. That is all I really need.</p></pre>edsonmedina: <pre><p>Stop the $GOPATH nonsense.</p></pre>jfurmankiewicz: <pre><p>Difficult to adopt Go in a locked down corporate environment, due to its insistence on pulling dependencies directly from git, instead of artifacts.</p> <p>This is unlike dep mgmt in all other modern languages (Java = Maven/Gradle, Rust = Cargo, Ruby = Bundler, Python = pip).</p> <p>Makes SOC2 compliance really hard.</p> <p>Recommendation I got from Go experts was to check in dependency source code directly into our project. That generated laughter from my existing Java devs. </p></pre>_mattlondon: <pre><p>Code duplication to work around the type system is the biggest pain for me, e.g. when handling database queries to get entities from a database (i.e. classic web backend stuff) we have to repeat the same function that is 99% identical to all the others functions in the package, but just use a different type from each other.</p> <p>This was highlighted perfectly by this twitter post: <a href="https://twitter.com/yogthos/status/883058510275149826" rel="nofollow">https://twitter.com/yogthos/status/883058510275149826</a></p> <p>The &#34;solutions&#34; of reflection and writing self-generating code just don&#39;t really work for the teams I am working in (i.e. loosely-coupled, distributed teams working semi-independently on the same codebase). These approaches require too much coordination &amp; maintenance and are too brittle and easy to break. There are some third party libraries that abstract away the database stuff sure, but a) the database example is an example (i.e. this occurs with non-database code too), and b) not all databases can use the common third party libraries for various reasons.</p> <p>Right now the copy-paste approach that appears to be the de facto &#34;work around&#34; has its own problems by people just blindly copying chunks around without double-checking what they are copying which can lead to subtle bugs if the logic is not checked.</p> <p>I dont really care what name is used (&#34;generics&#34; or otherwise), but <strong>some way of allowing a method to operate on objects of various types while providing compile-time type safety</strong> would make my life in Go a lot nicer.</p> <p>In my experience of working with people who are coming to Go but are used to other languages, the lack of a way to operate on objects of various types whole providing compile-time type safety is a <em>major</em> stumbling block to them getting up to speed. As mentioned in the blog post, it is hard to &#34;unlearn&#34; the more sophisticated type systems from other common, widely used languages so people struggle getting their head around Go.</p></pre>adelowo: <pre><p>removal of named return values.</p></pre>saturn_vk: <pre><ol> <li>Some kind of generic support. Even the stdlib needs this. </li> </ol> <blockquote> <p>func (s *set) Put(value T) where T is io.Reader, io.Writer</p> <p>type Node struct { value T } where T</p> </blockquote> <ol> <li>Sum types would be quite useful, especially in certain places of the stdlib, like the ast.</li> </ol> <blockquote> <p>type Type sum { Array ArrayType, Map MapType, ... }</p> <p>switch v:= typ { case Array: ... }</p> </blockquote> <ol> <li>I&#39;ve wanted for quite some time for &#34;extension&#34; methods to exist. Packages like &#34;strings&#34; or &#34;bytes&#34; can be reimplemented, so that once imported</li> </ol> <blockquote> <p>&#34;Foo&#34;.HasSuffix(&#34;oo&#34;)</p> </blockquote> <p>Would be valid</p></pre>Kraigius: <pre><p>I got to say, expvar is kind of cool.</p> <p>However, I&#39;m a bit annoyed that not only it automatically register both memstats and cmdline but there&#39;s no way can unregister any metrics. If you don&#39;t want to expose those metrics there&#39;s nothing you can do.</p> <p><em>edited grammar</em></p></pre>metakeule: <pre><p>Why not taking something out of the language? What are the problems &#34;goto&#34; was supposed to solve?</p></pre>YEPHENAS: <pre><p>They are useful for code generation.</p></pre>muehsam: <pre><p>One thing that has always bugged me was <code>uint32</code> and <code>rune</code>, as well as <code>uint8</code> and <code>byte</code>, being identical. Until recently, there was no other way that two differently named types could be identical, and I still think alias types should be used sparingly, if at all.</p> <p>They&#39;re also semantically different: <code>uint32</code> and <code>uint8</code> are just numbers of a specific size, there is no reason why it should be possible to cast a slice of them into a string, or the other way around, or even weirder, why you can cast single one of them into a string but get the respective Unicode code point. However, for <code>byte</code> and <code>rune</code>, those results are what you&#39;d expect. Similarly, one would expect <code>fmt.Print(&#39;A&#39;)</code> to output an <code>A</code>, when it in fact prints <code>65</code>.</p> <p>They should of course still be castable, and you should still be able to do arithmetic with <code>byte</code> and <code>rune</code>. But I think there is little gained from treating the types as aliases, as most programmers probably know if they want to use their variable as an unsigned number, a Unicode code point, or a raw byte.</p></pre>hbonly: <pre><p>not work on no fpu arm need standard gui can not build bundle work as iphone lib</p></pre>gopher1717: <pre><p>Final variables. Useful for types that aren&#39;t allowed as const</p> <pre><code>var final ErrNoRows = errors.New(&#34;sql: no rows&#34;) </code></pre> <p>Of course, this would be allowed in any context, not just in global variables.</p></pre>myringotomy: <pre><p>It&#39;s remarkable to me that most of the things people want added are already in Crystal.</p></pre>slowratatoskr: <pre><p>you have a good point but as far i know Crystal has no real parallelism</p></pre>myringotomy: <pre><p>It has go style channels but true multithreading is still in the pipeline.</p></pre>slowratatoskr: <pre><p>i hope it succeeds. its a nice language</p></pre>shovelpost: <pre><p>I am pretty sure the millions of Crystal developers will be delighted.</p></pre>shark1337: <pre><p>Yeah, but Crystal is still a new language. I&#39;m loving it as well :)</p></pre>kaeshiwaza: <pre><p>What make the simplicity of Go, what we have or what we don&#39;t have ?</p></pre>opiniondevnull: <pre><p>On the generics front, Typescript really does this so well and seems to make sense in the overall Go view of simplicity. Interfaces can be used both for data and for functions. Most of the time when using it for data you greatly remove the overhead of converting and just say &#34;I need a struct with an string named A and a array of ints named B&#34;. Any struct that has that matches and greatly simplifies readability.</p></pre>funny_falcon: <pre><p>I want &#34;slice with sliced capacity&#34; to become default, ie <code>a=b[x:y]</code> to be equivalent to <code>a=b[x:y:y]</code></p></pre>edsonmedina: <pre><p>Exceptions.</p></pre>allowthere: <pre><p>I&#39;ll answer in a classical &#34;Go&#34;-like answer[1]:</p> <p>Can we remove closures?</p> <p>Closures are nice when order of execution doesn&#39;t matter. For example, if</p> <pre><code>A() B() C() </code></pre> <p>isn&#39;t guaranteed to happen in any particular order (or happen at all - by lazy), closures are great (because you don&#39;t look at order anyways). But in Go, it gets confusing. For example:</p> <pre><code>MyStruct.Prepare(func(){fmt.Println(&#34;B&#34;)}) fmt.Println(&#34;A&#34;); MyStruct.Do() </code></pre> <p>would print A and then B, opposite of what the simple reading would show. This seems like a strangely &#34;functional&#34; feature in imperative-land.</p> <p>[1]. Yes. I know it ain&#39;t happening for many reasons. But let&#39;s put the idea out there</p></pre>qaisjp: <pre><p>Why? Just don&#39;t use closures if you can&#39;t understand them</p></pre>allowthere: <pre><p>I &#34;understand&#34; closures. It just doesn&#39;t &#34;read&#34; well</p></pre>qaisjp: <pre><p>It works fine in languages like Lua and JavaScript, and Go isn&#39;t that different in syntax.</p></pre>nevyn: <pre><p>Your example has nothing to do with closures, Eg.</p> <pre><code>MyStruct.Prepare(fmt.Println, &#34;B&#34;) fmt.Println(&#34;A&#34;); MyStruct.Do() </code></pre></pre>shark1337: <pre><p>Haha, I was thinking the same from the first time</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

450 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传