This weekly snapshot includes major changes to the reflect package and
the os.Open function. Code that uses reflect or os.Open will require
updating, which can be done mechanically using the gofix tool.
The reflect package's Type and Value types have changed. Type is now
an interface that implements all the possible type methods. Instead
of a type switch on a reflect.Type t, switch on t.Kind(). Value is
now a struct value that implements all the possible value methods.
Instead of a type switch on a reflect.Value v, switch on v.Kind().
See the change for the full details:
http://code.google.com/p/go/source/detail?r=843855f3c026
The os package's Open function has been replaced by three functions:
OpenFile(name, flag, perm) // same as old Open
Open(name) // same as old Open(name, O_RDONLY, 0)
Create(name) // same as old Open(name, O_RDWR|O_TRUNC|O_CREAT, 0666)
To update your code to use the new APIs, run "gofix path/to/code".
Gofix can’t handle all situations perfectly, so read and test the
changes it makes before committing them.
Other changes:
* archive/zip: add func OpenReader, type ReadCloser (thanks Dmitry Chestnykh).
* asn1: Implement correct marshaling of length octets (thanks Luit van
Drongelen).
* big: don't crash when printing nil ints.
* bufio: add ReadLine, to replace encoding/line.
* build: make the build faster, quieter.
* codereview: automatically port old diffs forward,
drop Author: line on self-clpatch,
recognize code URL without trailing slash.
* crypto/block: remove deprecated package.
* crypto/des: new package implementating DES and TDEA (thanks Yasuhiro
Matsumoto).
* crypto/ecdsa, crypto/rsa: use io.ReadFull to read from random source
(thanks Dmitry Chestnykh).
* crypto/rsa: add 3-prime support,
add support for precomputing CRT values,
flip the CRT code over so that it matches PKCS#1.
* crypto/x509: expose complete DER data (thanks Mikkel Krautz).
* doc: new "Functions" codewalk (thanks John DeNero).
* doc/roadmap: add sections on tools, packages.
* fmt: allow %U for unsigned integers.
* gc: fixes and optimizations.
* go/printer, gofmt: use blank to separate import rename from import path.
* go/scanner: better TokenString output.
* go/types: new Go type hierarchy implementation for AST.
* godashboard: show packages at launchpad.net (thanks Gustavo Niemeyer).
* gofix: add -diff, various fixes and helpers.
* gotest: fix a bug in error handling,
fixes for [^.]_test file pattern (thanks Peter Mundy),
handle \r\n returned by gomake on Windows (thanks Alex Brainman).
* gotype: use go/types GcImporter.
* govet: make name-matching for printf etc. case-insensitive.
* http: allow override of Content-Type for ServeFile,
client gzip support,
do not listen on 0.0.0.0 during test,
flesh out server Expect handling + tests.
* image/ycbcr: new package.
* image: allow "?" wildcards when registering image formats.
* io: fixes for Read with n > 0, os.EOF (thanks Robert Hencke).
* ld: correct Plan 9 compiler warnings (thanks Lucio De Re),
ELF header function declarations (thanks Lucio De Re),
fix Mach-O X86_64_RELOC_SIGNED relocations (thanks Mikkel Krautz),
fix Mach-O bss bug (thanks Mikkel Krautz),
fix dwarf decoding of strings for struct's fieldnames (thanks
Luuk van Dijk),
fixes and optimizations (25% faster).
* log: generalize getting and setting flags and prefix.
* misc/cgo/life: enable build and test on Windows (thanks Alex Brainman).
* misc/vim: add plugin with Fmt command (thanks Dmitry Chestnykh),
update type highlighting for new reflect package.
* net: disable multicast tests by default (thanks Dave Cheney),
sort records returned by LookupMX (thanks Corey Thomasson).
* openpgp: Fix improper := shadowing (thanks Gustavo Niemeyer).
* os: rename Open to OpenFile, add new Open, Create,
fix Readdir in Plan 9 (thanks Fazlul Shahriar).
* os/inotify: use _test for test files, not _obj.
* pkg/path: enable tests on Windows (thanks Alex Brainman).
* reflect: new Type and Value API.
* src/pkg/Makefile: trim per-directory make output except on failure.
* syscall: Add DT_* and MADV_* constants on Linux (thanks Albert Strasheim),
add Mmap, Munmap on Linux, FreeBSD, OS X,
fix StartProcess in Plan 9 (thanks Fazlul Shahriar),
fix Windows Signaled (thanks Alex Brainman).
* test/bench: enable build and test on Windows (thanks Alex Brainman).
Apologies if we missed anyone in the list above. We appreciate all your help.
To see a full list of changes between this and the previous release,
after updating, run:
hg log -r weekly.2011-04--04:weekly.2011-04-13
Enjoy.
Andrew
http://codereview.appspot.com/4395044
If you patch it in, does it fix the build for you?
Andrew
Omitted from these notes is another notable change: the O_CREAT flag
has been removed in favor of the correctly-spelled O_CREATE.
Hooray!
Andrew
It's what ken always wanted.
-rob
If you're not able to sign the CLA, then perhaps you could just
post the list of warnings?
Andrew
> The reflect package's Type and Value types have changed. Type is now
> an interface that implements all the possible type methods. Instead
> of a type switch on a reflect.Type t, switch on t.Kind(). Value is
> now a struct value that implements all the possible value methods.
> Instead of a type switch on a reflect.Value v, switch on v.Kind().
> See the change for the full details:
> http://code.google.com/p/go/source/detail?r=843855f3c026
I feel a little uncomfortable with the reduced compile time checking.
Before you had to state what you thought the value was and then try to
call a method. If there was a mismatch, the compiler would stop you.
You could define functions that accepted only specific kinds of types.
And you could easily see only the functions relevant to your kind of
type. What were the developers', particularly Russ's, thoughts on
these issues when the API decision was made?
The changes are almost entirely driven by a need to reduce the allocations required by the reflect library to improve performance.
-rob
It's probably not a great idea.
I've been thinking about adding a few methods to Kind for
IsInt
IsUint
IsFloat
IsComplex
> Is it safe to check that value is a number this way?
>
> if vk >= reflect.Int && vk <= reflect.Complex128 {
> // Any number: IntXX, FloatXX, ComplexXX
> }
Why would this be useful? In order to get or set
the value you need to know which class it is so
you can call the right methods.
Russ
case Int, Int8, Int16, Int32, Int64:
then there's no reason the compiler can't do
that just as or more efficiently than the
range you asked about before, without
having to add a second variant of Kind.
Russ
Thanks for the help.
Russ
Forgive my impertinence, but I have to question the wisdom of wanting to
treat all these types as boolean. Surely you have to know anyway, for
each type, the conditions under which it will be considered "true".
I think there's a good reason why the Go language itself doesn't support
automatic conversion to boolean. It has been one of the more insipid pitfalls
for other languages, especially JavaScript and PHP.
--
.O. | Sterling (Chip) Camden | http://camdensoftware.com
..O | ster...@camdensoftware.com | http://chipsquips.com
OOO | 2048R/D6DBAF91 | http://chipstips.com
-rob
It gets even worse in PHP (as most things do):
if (strpos("xyzzy", "x")) // Fails, because 0 is false
if (strpos("xyzzy", "x") != false) // Still fails, because 0 == false
if (strpos("xyzzy", "x") !== false) // Simon says... now it works
Automatic conversions are supposed to be a convenience, but sometimes they
end up being a source of confusion instead.
Had I not been without internet the last couple of days I could have incorporated these changes into the Golang tutorial I've just given at ACCU in the UK. Guess I'll have to update the code in the reflection section over the weekend so that people playing along offline can get it to work :)
Ellie
Eleanor McHugh
Games With Brains
http://feyeleanor.tel
----
if _, ok := reality.(Reasonable); !ok { panic(reality) }
He's not the only one :)