We have a couple of examples:
http://code.google.com/p/go/source/browse/misc/cgo/gmp/gmp.go?r=release
AGL
Are you suggesting a canonical matrix package, or special syntax
support for them also?
The former is certainly a good idea. Patches welcome :)
AGL
It looks a lot like Limbo (and its source tree looks a lot like Inferno :D).
I quickly looked at the channel primitives, but I did not see an
equivalent for Limbo's "alt". Am I missing something, or is this not
directly implemented?
Thanks,
-- vs
You want:
http://golang.org/doc/go_spec.html#Select_statements
AGL
As a rough approximation C++ compilation speed grows exponentially
with the size of the codebase. When you have a few million lines of
code to recompile it starts to matter a lot more. An example is
OpenOffice. It takes hours and hours to compile OpenOffice from
sources and it's only 8 million lines of code. Some proprietary
codebases are probably larger.
Kai
It's an issue if you build large programs (like a lot of Google's software, not coincidentally.) Try a clean build of Chrome sometime — it takes over an hour on my MacBook Pro.
—Jens
Say you have small apps/plugins, imagine widgets on
desktop you want to run on native code.
Let's say you have a bunch of devices, some of them are x86
based machines, some are ARM chip machines.
What if, you can "install" the these tiny apps by pushing the
go src, and on the fly compile it? If compile speed is always
very fast. this becomes possible.
and you can "distribute" this single src across the board.
Like say Chrome OS on desktop/netbooks that has
both x86 and ARM cpus.
--
Omnem crede diem tibi diluxisse supremum.
Besides other answers: when you can build a whole program in less than
a second it permits you to change your workflow in interesting ways.
Ian
--
> Go's main competition is the D programming language, so really, we need to compare Go to D.
I agree; this was my first reaction too when I heard of Go. I have not coded in D, but I've read through the documentation and it looked very good — not as radical a change as Go, but a "C++ done right" with no awkward backward-compatibility issues.
The deal-breaker for me with Go is the lack of object-oriented programming. The only other contemporary language I can think of that doesn't support objects is Lua; it's understandable there because Lua is meant to be tiny and stripped-down (and you can implement JavaScript-style objects in about 100 lines of Lua anyway.) For a larger-scale language, leaving out OOP seems kind of, well, nuts to me.
(I'm sure some people will argue that Go's interfaces are object-oriented; but without inheritance, they're not. They're basically equivalent to COM, an architecture I've tried really hard to stay away from.)
—Jens
I have not done much programming in D, but from reading the docs I
think Go and D really have different goals. D seems to me to be
aiming for a better C++, bringing in all the interesting and useful
features from C++ and even from some other languages. Go is a
language designed from scratch to have relatively few powerful
concepts. It intentionally does not have a lot of features.
This is all just my opinion, of course, and may be wrong-headed.
Ian
var ch1 chan int;
var ch2 chan float;
I'm with you so far.
> We'd like to
> receive from whichever one is ready and return the value as an int.
> First-class communication would allow us to do something like
>
> let the_int = sync (choose [wrap (receive ch1) (fun i -> i); wrap
> (receive ch2) (fun f -> int_of_float f)])
In Go, this isn't all packed onto one line but is largely the same:
var i int;
select {
case j := <-ch1:
i = j;
case f := <-ch2:
i = int(f);
}
Russ
> The deal-breaker for me with Go is the lack of object-oriented
> programming. The only other contemporary language I can think of
> that doesn't support objects is Lua; it's understandable there
> because Lua is meant to be tiny and stripped-down (and you can
> implement JavaScript-style objects in about 100 lines of Lua
> anyway.) For a larger-scale language, leaving out OOP seems kind of,
> well, nuts to me.
>
> (I'm sure some people will argue that Go's interfaces are
> object-oriented; but without inheritance, they're not. They're
> basically equivalent to COM, an architecture I've tried really hard
> to stay away from.)
Embedding anonymous fields provides a form of inheritance. It's quite
powerful in practice.
Ian
On Wed, Nov 11, 2009 at 1:21 AM, Jens Alfke <je...@mooseyard.com> wrote:
> (I'm sure some people will argue that Go's interfaces are object-oriented; but without inheritance, they're not. They're basically equivalent to COM, an architecture I've tried really hard to stay away from.)
Just $0.02: I'd argue that subtype polymorphism (exactly what
interfaces give you) is more central to OOP than inheritance (in the
usual sense of implementation inheritance).
Can you sensibly use inheritance without polymorphism? Kinda hard
since you need to statically decide what method to run at every call
site. Can you sensibly use polymorphism without inheritance? You
betcha, but you may have to write a little more code (for example to
do forwarding instead).
Think of it this way: Using an interface, you "reuse" all the code
that "understands" that interface. Using inheritance, you reuse (some
of) the code from your class up to your base class(es). I doubt that
the path up your class hierarchy contains more code than all the
potential client applications accepting your interface.
Yes, you can make some nice things happen with inheritance, heck I
found a nice way to use a multiply-inherited mixin in Python today,
even made sense remotely in the design. But I can certainly see why
some people would prefer not having to deal with such constructions.
:-D
Cheers,
Peter
--
Peter H. Froehlich <http://www.cs.jhu.edu/~phf/>
Senior Lecturer | Director, Johns Hopkins Gaming Lab
Example? Link suffices.
> On Wed, Nov 11, 2009 at 1:36 AM, Ian Lance Taylor <ia...@google.com> wrote:
>> Embedding anonymous fields provides a form of inheritance. It's quite
>> powerful in practice.
>
> Example? Link suffices.
http://golang.org/doc/effective_go.html#embedding
Ian
I don't think Go's model is much different than
what you're writing, it just has a different syntax.
John Reppy and Rob Pike are certainly aware of each
other's work in this area.
More generally, you're already an expert on all the things
you can think of that Go doesn't have. It's much more
interesting to look at the new things Go has.
http://golang.org/doc/go_faq.html#Why_doesnt_Go_have_feature_X
Russ
3. structs as the key type for built-in maps
That said, I find the Go developers courageous for leaving a lot of stuff out. I like the D language which attempts to provide a modern C++, but it seems to be falling in the same complexity trap as C++.
From a quick initial look, it seems to be a nice middle ground between the relative simplicity of C and means of abstraction in C++/Java.
Take care,
Daniel de Kok
You might not believe how fast development of a large telecom system
in C/C++ can get bogged down by its build process, especially one
which generates code from a few models and little languages. Serious
development time, expensive tools, dedicated hardware, just to keep it
sane. Incremental builds definitely help, but create a tradeoff where
you take a big hit every time the view into the codebase becomes
corrupt, or you make a new one (daily, since you also want everyone
working in isolated views so they're not debugging each other's
half-done work).
Key improvements in Go that make it suited for large systems work
(IMO): easy threadish management and communication, an inherently
fast/scalable build system that explicitly manages its dependencies,
almost-C syntax, and imperative semantics (read: understood by today's
systems engineers, vs functional Haskell with different/cleaner syntax
and trickier/pure I/O).
To me, the cost of transitioning to the language pale next to the cost
and effort put into making big systems build fast. When Go is
available for the types of platforms on which big systems are done
(eg, Linux or a proprietary OS on a PowerPC), I'd be surprised if it's
not seriously considered.
Jason Catena
We have not discussed an exponentiation operator. The language is not
set it stone, but I'm not sure an exponentiation operator would be
appropriate for a language like Go.
Ian
> I think I'd like to see integration with the Google App Engine (GAE)
> very early on.
We are also interested in App Engine integration and we hope it will
happen reasonably soon.
Ian
On Wed, Nov 11, 2009 at 17:55, Ian Lance Taylor <ia...@google.com> wrote:
> We are also interested in App Engine integration and we hope it will
> happen reasonably soon.
Wouldn't that terribly cripple Go, as AppEngine allows only
single-threaded apps? Or would you want to lift that limitation for
Go?
--
Cheers,
Sverre Rabbelier
Well, the last time Ken Thompson (one of the three designers of Go)
came up with a language we got C. I'd put my money on him, and his
ability, rather than a popularity poll of random developers.
Languages designed by committes are never pretty - Fortran, COBOL,
Ada...
--
Nec tecum possum vivere nec sine te
Yes, but their explanation is the problem. They say:
>they have profound effect on library and interface specification
So if you leave out exceptions and add them in later,
all code , base libraries and so on, using the "old go version without
exceptions" will become legacy code compared
to the "new code" with exceptions. That scenario will be very very
messy.
If they have a new concept that replaces exceptions, they should
figure it out before substantial code is written.
I think we would want to lift that limitation for Go. (I'm actually
not that familiar with AppEngine personally.)
Ian
On Wed, Nov 11, 2009 at 19:42, Ian Lance Taylor <ia...@google.com> wrote:
> I think we would want to lift that limitation for Go. (I'm actually
> not that familiar with AppEngine personally.)
I think the restriction is mainly to make it easier to do resource
tracking, but I don't know the details (ask appengine team @google I'd
guess :P). Also, how would go deal with DeadlineExceededException?
AppEngine limits apps to 30s of execution time, with no exception
support in go there'd be no way to deal with that?
--
Cheers,
Sverre Rabbelier
My goal, which started this tangent: Data as objects, not in Python. :)
I missed this in the list of Go's goals.
Personally, I'm looking forward to a bunch of people deciding Go isn't
elaborate enough for them, and going away, so everyone else can spend
time getting work done with it instead of attacking and defending it.
(For example, if you can write Go programs in Unicode, why doesn't it
use APL operators? Surely they're more complete, and it would make Go
ever so much more succinct and useful.)
Hopefully the remaining community will be larger than Plan 9's and Inferno's.
Jason Catena
1. Lightweight Processes Only on the Same Machine?
I'd read the Erlang book, but the language is too far removed from my
expertise for me
to pursue it seriously. I wished for somebody to bolt Erlang's
lightweight process idea
onto a C-like language (which is imho the only major good thing about
Erlang; things
like "matching" and single-assignment just don't make sense to me).
Looks like the Go
team was thinking along similar lines!
A key limitation I see is that the communicating processes have to be
on the same machine.
Due to lack of operator overloading, this cannot be fixed by libraries
and still maintain
the same syntax as local channels.
I hope this gets added that at some point.
2. Crashproofing?
A second major advantage of Erlang is that it guarantees that a
badly-written process
cannot crash other processes. That allows a Erlang program consisting
of a single OS process
to monitor itself and restart components that crash.
I dont think Go can provide such strong guarantees. You'll need an
external program to monitor
the running process. This increases deployment pain.
I wonder if this can be addressed since Go is a compiled language. Are
there OS and CPU
facilities that can be used to wall off goroutines from each other?
3. Love the lack of type conversion (int -> long long etc).
I just debugged a nasty problem to do with implicit shifting in 32
bits instead of 64.
Ranga
> I think that language is beautiful. I posted a moment ago that I want to do
> my dissertation work in it.
Thanks!
> I think that the adoption or the lack of will make all the difference.
Yes.
> Is there an issue with internal competition with Guido Van Rossum and his
> work with Python?
No, Google works on lots of different things.
Ian
package main
import "fmt"
import "http"
func main() {
s := "http://www.michaelbernstein.info/";
r,_,_ := http.Get(s);
if r != nil {
var z []byte;
n := -1;
for n != 0 {
n, _ = r.Body.Read(z);
fmt.Printf("len(z) is %d\n", len(z));
}
r.Body.Close();
}
else
{
fmt.Printf("Error Occured somewhere\n");
}
}
Michael Bernstein
mnber...@gmail.com
> I wonder if this can be addressed since Go is a compiled language. Are
> there OS and CPU
> facilities that can be used to wall off goroutines from each other?
Not at present. However, the lack of pointer arithmetic, and array
bounds checking, make it hard for one goroutine to crash another
accidentally.
Ian
I think that we have is the C calling interface as a defacto standard.
For more complex issues we have programs like swig.
I agree that more work could be done in this area.
Ian
On Wed, Nov 11, 2009 at 4:23 PM, Ian Lance Taylor <ia...@google.com> wrote:
>
> I think that we have is the C calling interface as a defacto standard.
>
> For more complex issues we have programs like swig.
>
> I agree that more work could be done in this area.
>
> Ian
>
--
Omnem crede diem tibi diluxisse supremum.
> I'm not sure that template/generics are really that needed given how
> the type system works, provided that compilers can seize opportunities
> to resolve types at compilation time when possible (for instance if a
> function takes a parameter that needs to be a certain interface, if
> you call it with values of completely different types that all
> implement that interface, does the compiler generate one version of
> the function for each type?)
No. An interface is a run-time object: a pointer to the underlying
primitive or struct plus a pointer to the vtable for this interface.
It's essentially pure runtime polymorphism separate from any
considerations of data storage or layout. Consequently, there's
nothing you can do with an interface but invoke one of its methods.
--
GMail doesn't have rotating .sigs, but you can see mine at
http://www.ccil.org/~cowan/signatures
package main
import "fmt"
import "http"
import "os"
func main() {
s := "http://www.golang.org/";
r, _, err := http.Get(s);
if err != nil {
fmt.Printf("Error: %v\n", err);
return;
}
var buf [4096]byte;
for {
n, err := r.Body.Read(buf[0:len(buf)]);
if err != nil && err != os.EOF {
fmt.Printf("Error: %v\n", err);
return;
}
fmt.Printf("%d bytes were read\n", n);
if err == os.EOF {
break;
}
}
r.Body.Close();
}
package main
import "fmt"
import "http"
import "os"
func main() {
s := "http://www.golang.org/";
r, _, err := http.Get(s);
if err != nil {
fmt.Printf("Error: %v\n", err);
return;
}
var buf [1]byte;
for err != os.EOF {
_, err = r.Body.Read(buf[0:len(buf)]);
fmt.Printf("%s", buf[0:len(buf)]);
if err != nil && err != os.EOF {
fmt.Printf("Error: %v\n", err);
return;
}
}
r.Body.Close();
}
vs.
package main
import "fmt"
import "http"
import "os"
func main() {
s := "http://www.golang.org/";
r, _, err := http.Get(s);
if err != nil {
fmt.Printf("Error: %v\n", err);
return;
}
var buf [4096]byte;
for err != os.EOF {
_, err = r.Body.Read(buf[0:len(buf)]);
fmt.Printf("%s", buf[0:len(buf)]);
if err != nil && err != os.EOF {
fmt.Printf("Error: %v\n", err);
return;
}
}
r.Body.Close();
}
Michael Bernstein
mnber...@gmail.com
I don't think you should print buf[0:len(buf)], you should instead
print buf[0:n], where n replaces the _ in the previous line (i.e. n is
the number of bytes read).
I'm not sure if that will fix all your problems, but that's at least
one problem.
Another thing (off the top of my head) is that you might, after the
for loop, try printing a "\n" to see if that flushes anything. That
might just be total crack, though.
n, err := r.Body.Read(&buf);
fmt.Printf("%s", buf[0:n]);
Michael Bernstein
mnber...@gmail.com
> This leads me to an interop question. When calling c routine from
> go. What sort of "gotcha" should I pay attention to?
If you pass a pointer to C, make sure you keep a copy in Go, since
otherwise Go's garbage collector might pick it up.
C routines run in their own thread.
Ian
Thanks for the help.
Michael Bernstein
mnber...@gmail.com
> My pet project currently is a game engine written in C++ with
> javascript bindings for game scripting etc. and actually I believe
> that goroutines/channels would be awesome for the purpose of scripting
> game objects. Since the compiler is very fast, I was wondering if
> there's any plan to include it as a package, allowing to compile go
> code at runtime? Maybe the exp.eval is planned to become such a thing?
> That would be pretty awesome.
We have thought about that sort of thing, but nothing concrete yet.
Ian
--
> On Wed, Nov 11, 2009 at 4:43 PM, Antoine Chavasse <a.cha...@gmail.com> wrote:
>
>> I'm not sure that template/generics are really that needed given how
>> the type system works, provided that compilers can seize opportunities
>> to resolve types at compilation time when possible (for instance if a
>> function takes a parameter that needs to be a certain interface, if
>> you call it with values of completely different types that all
>> implement that interface, does the compiler generate one version of
>> the function for each type?)
>
> No. An interface is a run-time object: a pointer to the underlying
> primitive or struct plus a pointer to the vtable for this interface.
> It's essentially pure runtime polymorphism separate from any
> considerations of data storage or layout. Consequently, there's
> nothing you can do with an interface but invoke one of its methods.
To be precise, you can also convert it another interface or back to
its dynamic type.
Ian
> Does this mean a system trap in a goroutine won't kill the whole
> process?
Fair point, currently a division by zero or something like that will
kill the entire process.
Ian
On Thu, Nov 12, 2009 at 01:32, Jason <jki...@gmail.com> wrote:
> I've had some success with a factory function and a public interface/
> private implementation. Is this the way we do encapsulation in Go?
Mhhh, Misko Hevery often rants about the abuse of 'new' in say Java,
where people should only be using it to construct basic data types,
and should be using a factory pattern (or such) otherwise. Looks like
this is pretty much what Go encourages, sweet.
--
Cheers,
Sverre Rabbelier
> However one thing that I would like to see before I start coding in
> database connectivity. Would like to know if, how and when it is
> planned.
We have no specific plans but several people have expressed an
interest in it. I would encourage somebody to propose a plan for how
it should be done.
Ian
At a high level, I like the language. Dynamic interface matching is
pretty nice (although maybe not as novel as the authors think; a lot
of us have used Objective-C, you know!). I don't mind the
Speaking of this, working on my toy system, I found that the ", ok"
technique was really valuable. I was playing with rendering days of
the week and was pleasantly surprised when this construct worked:
func (d dayOfWeek) String() string {
s, ok := dayNames[d];
if ( ok ) {
return s;
}
return "Unknown";
}
Of course, I'd _like_ to have _any_ way to restrict my "day of the
week" value to be within the valid range of 0-6. There just doesn't
seem to be a way to do this, or even to reliably make the user of the
class do something ugly to set off alarm bells. For example, one thing
I tried to do was this:
func NewDay(dow DayOfWeek) *Day {
return &Day{ dayOfWeek(dow) };
}
Where I have a set of "DayOfWeek" (note initial caps) const defined.
But I can happily just pass in "8" without even having to typecast it!
Without constructors, I think this is going to create some major pain
(or at least not solve this pain where other languages do).
Also, don't take this as a criticism of not having enum types, which
would solve this case, but it appears to be a global problem. Let's
say I have a struct with a URL string in it. The caller can set that
to whatever crazy value they want with zero validation (until possibly
_much_ later; this is a Heisenbug waiting to happen). This seems to be
a problem with the object-orientation of Go.
I've had some success with a factory function and a public interface/
private implementation. Is this the way we do encapsulation in Go?
> Why the decision to make the export condition an upper-case first
> symbol?
>
> It seems to me that this implies that if I decide to make a non-
> exported symbol exported later, or vice-versa, I then have to change
> all references to it within the package to match the new name, instead
> of making a single-location change. This seems like a pretty big
> hassle.
Yes, we thought about that. In the end we felt that the convenience
of being able to see immediately whether a type or variable is
exported outweighed that issue.
Ian
> Where can I get one of those Go T-Shirts (ref: http://www.youtube.com/watch?v=wwoWei-GAPo)?
Well, if we do make them available, we'll certainly announce it here.
Ian
> On Nov 11, 4:30 am, Robert Schonberger <rschonber...@gmail.com>
> wrote:
>> I love it! what do people think of Go? what are the 1st questions?
>
> I know it compiles very quickly and all, but I really wish it had a
> repl. When I'm trying to interface with a website's API, or dealing
> with XML or JSON data, being able to incrementally write code to
> extract what I need makes me very productive.
Yes, that can be very effective. There is an experimental
interpreter, but the approach can be an awkward fit with a statically
compiled language like Go.
Ian
So, why not require an explicit cast if I use a value not of that
type. E.g.:
type DayOfWeek int
const {
Sunday DayOfWeek = iota;
// blah, blah...
}
func f(dow DayOfWeek) {
// Blah
}
f(42); // Compiler should fail, no? C'mon, I'm trying here by giving
you all those const...
f(DayOfWeek(42)); // Okay, buddy, you're on your own, then, if you
_insist_