Because the math package is not polymorphic, you have to write them
yourself. The inliner can cope with these simple functions
http://code.google.com/p/go/source/browse/ssh/client.go?repo=crypto#452
> Could someone please tell me i'm just blind ?
Sadly there is no ternary form in Go.
http://golang.org/doc/go_faq.html#Does_Go_have_a_ternary_form
Cheers
Dave
you're in for a surprise, then :)
What do you want to see in it? I'm not sure how it solves the problem.
Rémy.
......I'm sorry, but i really can't believe it. I've read a thread were someone was saying "i don't want to add those function in math because it would release the pressure for generics". Since that was a few years ago, i really hoped someone would have taken care of that situation since then.So, what you mean is that every single project will have to redefine its own math library dealing with integer just because of pure ideology (on one side at least) ?I mean, this is such a trivial feature that the only fact that the solution to it is a subject of internal discussion gives me the creep. I don't mind coding my own min/max/abs functions, but i mind having to do it a LOT.
I was planning on starting a small project with go in the coming weeks, because i loved what I saw so far, but that kind of things is really like a huge stop sign in the middle of the road...Is anyone planning on creating a somewhat decent math package that anybody else would use ?
......I'm sorry, but i really can't believe it. I've read a thread were someone was saying "i don't want to add those function in math because it would release the pressure for generics". Since that was a few years ago, i really hoped someone would have taken care of that situation since then.So, what you mean is that every single project will have to redefine its own math library dealing with integer just because of pure ideology (on one side at least) ?
I mean, this is such a trivial feature that the only fact that the solution to it is a subject of internal discussion gives me the creep.
I think people here misunderstood me. I'm not entering the pro/cons of generics in GO debate (i've been writing Go for only 2 hours now, that would be a bit premature i guess), i'm just saying that you can't release a v1.0 programming language in 2012
that doesn't gives you those extremely common functions right of the shelves for built-in types (no matter how, using generics or hard-coding the functions , i absolutely don't care at all and have no opinion on that).
Especially one that advertises a "modern dynamic language" feeling.
If there is a math/int lib I know I won't use it.
-1
I think people here misunderstood me. I'm not entering the pro/cons of generics in GO debate (i've been writing Go for only 2 hours now, that would be a bit premature i guess), i'm just saying that you can't release a v1.0 programming language in 2012I think you'll find that we just did. Based on the uptick in mailing list and IRC traffic, I think it's been a success.
that doesn't gives you those extremely common functions right of the shelves for built-in types (no matter how, using generics or hard-coding the functions , i absolutely don't care at all and have no opinion on that).
Especially one that advertises a "modern dynamic language" feeling.I don't see how not providing min, max, and abs as language builtins solves this problem. If we had those, then people would want insert() and delete() and then people would want trunc() and ceil() and float. You may wish to argue that Min and Max should be in the math package, but the truth of the matter is that you can always write one yourself once and be done with it, and that there are many situations where min(a,b) is not really what you want; you may want min(...int) or any number of other things that only you and your application can implement correctly and efficiently.
what is min(a,b) equal to when a=interface{} and b=interface{}? for
that matter, what is it equal to when they are structs?
C
-rob
On Sat, Mar 31, 2012 at 10:15 AM, Benjamin G.
You're not the first to complain about the lack of a ternary operator
nor the first to wonder about min/max on non-float types. I'm sure
that I have wondered / complained about it (though perhaps not so
publicly / persistently) at some point in the past.
Have you spent much time with Go? If not, it's worth doing. Many who
have complained have found that they are OK with the lack of these
things. Still others have found they are not OK and gone on to using
other languages.
> Once again, i know that thing really IS minor, and i've made a more
> detailled answer above as to why this preoccupies me. Make no mistake, i've
> just spent the last weeks diving into some horribly bloated and highly
> advertised java web framework that solves pretty much everything useless and
> nothing useful, and the previous year dealing with overhyped highly
> advertised dynamic-language frameworks that tells people to basically write
> types in code comments and replace compilation with manual unit-testing.
>
> So you can't imagine how much i would LOVE to see go become the new
> mainstream language, at least for the server side. It's just that I know
> that those are the kind of minor things that me rebuke many (average)
> developers.
It really isn't a big deal to write your own IntMin and IntMax
functions when and where you need them. If the lack of something that
saves you 4 lines of code max is a deal breaker for using a language,
perhaps the "easier" languages are best for you. Personally, I would
love it if Go did not become "the new mainstream language." The Ruby
On Rails and node.js hype camps are really silly.
Op 30 maart 2012 19:42 heeft Benjamin G.
> Don't want to show disrespect, but anything more "modern" or "dynamic" ;) ?
> Plus, at least C gives you ternary if/then/else operator...You're not the first to complain about the lack of a ternary operator
nor the first to wonder about min/max on non-float types. I'm sure
that I have wondered / complained about it (though perhaps not so
publicly / persistently) at some point in the past.
Have you spent much time with Go? If not, it's worth doing. Many who
have complained have found that they are OK with the lack of these
things. Still others have found they are not OK and gone on to using
other languages.> Once again, i know that thing really IS minor, and i've made a more
> detailled answer above as to why this preoccupies me. Make no mistake, i've
> just spent the last weeks diving into some horribly bloated and highly
> advertised java web framework that solves pretty much everything useless and
> nothing useful, and the previous year dealing with overhyped highly
> advertised dynamic-language frameworks that tells people to basically write
> types in code comments and replace compilation with manual unit-testing.
>
> So you can't imagine how much i would LOVE to see go become the new
> mainstream language, at least for the server side. It's just that I know
> that those are the kind of minor things that me rebuke many (average)
> developers.It really isn't a big deal to write your own IntMin and IntMax
functions when and where you need them. If the lack of something that
saves you 4 lines of code max is a deal breaker for using a language,
perhaps the "easier" languages are best for you. Personally, I would
love it if Go did not become "the new mainstream language." The Ruby
On Rails and node.js hype camps are really silly.
> On Saturday, March 31, 2012 1:21:20 AM UTC+2, r wrote:
>>
>> On Sat, Mar 31, 2012 at 10:15 AM, Benjamin G.
>> > I'm not asking for much : just give me the name of one single language
>> > that
>> > doesn't provide min/max/abs for basic numerical types...
>>
>> C
>>
>> -rob
Op 30 maart 2012 19:42 heeft Benjamin G.
There are 12-15 numeric types (give or take). You'd like to see
Max/Min/Abs for them.
There are 61 functions in the math package, which all work on float64s
and seem to work quite well.
Having all of these 'trivial but required' functions would almost
double the size of the library, and you would lose the consistency you
already have with them working on floats and being well defined.
If you say you want just Int, then why not the other types? You can
already cast the integer types to floating types and use the library
that is already quite well defined.
- Jim
There's no reason the lack of min/max prevents you from writing
something hard. I've written non-basic Go programs for a few months
now, and I may have needed min/max once or twice, but my screen was
certainly never covered at 90% by tedious code. Whenever I needed
min/max more than twice (which actually never happened), I would have
written a little helper function somewhere.
I lack min, max as much as I would miss map, fold, or list
comprehensions. It may be annoying for a second, but that's all. What
do you need min/max for? Actually, if I had min/max in a language but
was proposed to get list/array comprehensions instead, I would not
hesitate to trade.
Why do you think it's horrible to have all Go developers in the world define
func max(a, b int) int { if a > b { return a }; return b }
It's a single line, not 4. But you don't put code in a language spec,
you put code in libraries. It takes as many lines of code to import a
library with a trivial function than to write it directly. If you
write the function yourself, you win the advantage of not falling in
the traps of special cases of the function you imported because it
didn't you what you think it did.
And, anyway, I only saw that function in people's code once in dozens.
Rémy.
Building on this point: as you use Go, you will encounter many occasions where a common 3-5 line helper function appears to be "missing": not just min/max, but also helpers to extract the keys or values from maps into slices, and helpers to gather results from a channel into slices, and helpers to map functions over elements of a map or slice in parallel, and.... you get the idea. Instead of providing oodles of libraries to handle all these cases, Go gives you a small, easy to remember set of powerful primitives and core libraries. This makes it easier to hold the language and libraries in your head, which means it's easier to write code without flipping back and forth to reference pages. As a result, you spend longer stretches of time in the programming flow, and you end up getting more done. This is something that you won't fully appreciate until you try using the language to write a real program.
Building on this point: as you use Go, you will encounter many occasions where a common 3-5 line helper function appears to be "missing": not just min/max, but also helpers to extract the keys or values from maps into slices, and helpers to gather results from a channel into slices, and helpers to map functions over elements of a map or slice in parallel, and.... you get the idea. Instead of providing oodles of libraries to handle all these cases, Go gives you a small, easy to remember set of powerful primitives and core libraries. This makes it easier to hold the language and libraries in your head, which means it's easier to write code without flipping back and forth to reference pages. As a result, you spend longer stretches of time in the programming flow, and you end up getting more done. This is something that you won't fully appreciate until you try using the language to write a real program.
I'll try to keep on trying that language and not let those missing helper-like functions bother me too much.
For what it's worth... Some of the plugins (vim for sure) in the misc/vim dir
of the release tarball provide useful documentation integration, and there's
the github.com/nsf/gocode autocompletion helper.
--
That which can be asserted without evidence, can be dismissed without
evidence.
It seems silly not to have such basic functions available.And no, it's not the 10 second cost of writing your own min/max functions, but the 20 minutes every new developer will waste trying to understand why they have to write a function that was built into whatever language(s) they were using before.
Go aims to be pragmatic. Sorry, but the absence of basic math functions - not pragmatic at all.
On Friday, March 30, 2012 11:43:27 PM UTC-4, John Asmuth wrote:
On Friday, March 30, 2012 8:59:46 PM UTC-4, Benjamin G. wrote:I'll try to keep on trying that language and not let those missing helper-like functions bother me too much.Glad to hear it. The 10 second cost of writing "func MinInt(x, y int) (r int) { if x < y { return x } return y }" are a small price to pay for the other benefits we see with go. Among which number the intentionally feature-poor approach of the designers that serves to keep the language lean and mean.
--
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/groups/opt_out.
It's not going to be added as a library function, becuause we would have to have one for {u}int{,8,16,32,64} and float{32,64}
Here ya' go. Almost 100% autogenerated as well.
I'm not sure if it is a good idea, but in case you cannot bear to
write these functions yourself.
https://godoc.org/github.com/pkg/math
> It's not going to be added as a library function, becuause we would have to have one for {u}int{,8,16,32,64} and float{32,64} or one using interface{}, and I'm sure you can see why neither of those are good optionsA justifiable use-case for overloading?
Also, the first time you need something as trivial as a max function, you're probably not going to actually add it as a function - I didn't want the extra function, so I calculated it inline. When should I refactor? After two operations? Three? What if I end up needing it two different modules, do I factor it out into a library? Not choices you want to spend time on. Distractions.
The problem, in my opinion, is that math.Max() exists - you want to do well, you've been taught not to "roll your own" when something is already available, so it's logical to think that's what you should be using - but you can't...
Anyhow, I've learned my lesson, and this is not a showstopper for me, so I'm moving on - bigger fish to fry :-)
> Overloading often just produces very, very poor, bloated APIs, and many of it's use cases can be better served by proper generics
Agreed - if this could be solved with generics (which I've heard the Go team is open to) that would be even better :-)
To fully accept the zen of Go (or the zen of any language), one must be willing and able to give some of their assumptions.
> I'm wanting to root for the Go team because I see a lot of complaints about what Go lacks. How about instead we sit down with the language for more than 1 hour so we can learn about the many, many other areas of what Go has gotten right.I'm thrilled about a ton of things in Go, and starting to strongly agree with what I had heard, that Go makes programming fun again :-)I also know C# and thought that was a nice language - I agree with your observations about overuse/abuse of generics though, and I'm not necessarily rooting for generics or any other specific feature.For all the reasons I explained previously, I do hope a solution is found, eventually, that facilitates implementing things like basic math operations in a practical, useful general-purpose form - the fact that it can't be done in a satisfying way right now, is an indicator that something is still missing.