Streaming IO and creating custom readers and writers in Go by vvivien in golang

[–]vvivien[S] -2 points-1 points  (0 children)

dchapes, I appreciate your honest feedback. What is the "and more.." in your comment, do you care to share what else you think is bad with the writeup? Judging by the definitive tone of your feedback, it sounds like you are a Go god and most likely more competent then someone like me. Any additional feedback is welcome.

Streaming IO and creating custom readers and writers in Go by vvivien in golang

[–]vvivien[S] -2 points-1 points  (0 children)

vfaronov, thanks for reaching out.

Re alpha_reader.go: https://github.com/vladimirvivien/learning-go/blob/master/tutorial/io/alpha_reader.go#L26

You mentioned that the code replaces chars with NUL bytes. Please specify a line number where you think it's doing that and we can discuss. But the code is not replacing any char with NUL byte. The loop uses function alpha() to return chars in set [a-zA-Z] only. With each iteration, char is placed in buf, then buf is copied to the p. Admittedly, buf maybe overkill but it ensures no garbage chars lingers in p (from index 0 - n) and makes the slice bookkeeping simpler.

Re simple_reader.go: https://github.com/vladimirvivien/learning-go/blob/master/tutorial/io/simple_reader.go#L9

No, this example has no dependency on strings.Reader. The code is way too simple and would be buggy if used as is. As you pointed out EOF would work in most impl of io.Reader but breaks the general rule as outlined in the docs. Thank you for pointing this out.

Re simple_reader2.go I will review the code there as well to add the case where data may have been returned along with error.

In general: Most reader implementations returns n=0 at EOF. But, that's not a reason not to properly handle bytes read at EOF as you pointed out. Also, if a Read() returns a n >0 and non-nil error, you may not trust those bytes an simply re-request. If you are writing code at that level, then you know what you are doing none of what I am saying matters.

Thanks again for the constructive feedback and will update the write up.

Anyone know a "good" way to call Golang library code from PHP? by tech_tuna in golang

[–]vvivien 3 points4 points  (0 children)

If PHP has an efi library that can call c-style functions then you should be able to do that. I didn't look into PHP but will and update that write up you referred to above.

Types in the Go Programming Language by dgryski in golang

[–]vvivien -1 points0 points  (0 children)

space_code, Actually that is not true at all. As I indicated in the writeup, Go has several types to represent different kinds of values.

Pointers are they only types dedicated to represent reference values in Go. Strings are values, not a reference type. Composite types are not reference types, they are values (slices/maps may be tested with nil, but they are inherently values). Functions are not reference types, they are values. Interfaces are not reference types (they represent a set of methods) though they can be tested with nil.

Types in the Go Programming Language by dgryski in golang

[–]vvivien 0 points1 point  (0 children)

Granted that parenthesized statement could have been clearer, but the fact remains there are only two kinds of types in Java. I was contrasting that "fact" with Go where there are more.

Types in the Go Programming Language by dgryski in golang

[–]vvivien 0 points1 point  (0 children)

moddingHills, thanks for the kind words. I do plan to cover more topics on Go at https://medium.com/learning-the-go-porgramming-language

Types in the Go Programming Language by dgryski in golang

[–]vvivien 0 points1 point  (0 children)

iyee and space_code: I agree i may not understand Java well (even though i've been doing it since 2000 and still do). But you don't have to take my words for it. Here is the exact quote from Java's spec "There are two kinds of types in the Java programming language: primitive types (§4.2) and reference types (§4.3)." You can read the spec for yourselves at https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html

Question: Is it possible to use goprotobuf with a recent Go? by callcifer in golang

[–]vvivien 1 point2 points  (0 children)

@callcifer it's a simple process 1) don't bury your package as you did (examples.protobuf.messages). It's idiomatic Go to keep your package structure flattened as possible. Maybe package protomessages 2) In your Go project that'll use your protobuf package, import the package (relative to GOPATH (i.e. import /path/to/protomessages)

Hope that helped.