On Thu, Sep 22, 2016 at 10:48 AM, Leandro Motta Barros <l...@stackedboxes.org>
wrote:
> I wonder if anyone would be willing to take a look at it, and give some
> advice on how to be more idiomatic or improve it somehow.

Not sure how to do this on GitHub if it's not a PR, I don't appear to be
able to leave line-level comments on the source, so I've inlined it. Sorry
for all the missing context. That being said, here are a few things I
noticed:

> parser := &parser{}
> parser.input = document
> parser.processor = processor
> parser.frag = parser.input
> parser.fragEnd = 0
> parser.textStyle = TextStyleRegular
> parser.linkTarget = ""
> parser.linkTargetLen = 0

This could be much more cleanly written with all the fields in the struct
literal, eg. the idiomatic way to write this would be:

> parser := &parser{
>    input: document,
>    processor: processor,
>    frag: document,
>    textStyle: TextStyleRegular,
> }

Also, don't forget that in Go all structs are initialized, so eg.
linkTargetLen and linkTarget which are 0 and the empty string respectively
dont need to be initialized at all since the zero value of an numeric type
is 0 and the zero value for a string is "".

Finally, be careful, doing parser := &parser{} is shadowing the struct
parser which may (or may not) be what you want.

> p.processor.OnStartDocument()

This is of course completely up to you, but it's idiomatic to just call
something like this "StartDocument", the "On" is normally elided.

> github.com/lmbarros/sbxs_go_markydown/markydown

The package would normally just live at the repo root in go; unless you're
expecting other subpackages to live in this repo. Right now I'd have to:

    import "github.com/lmbarros/sbxs_go_markydown/markydown"

but it might read better if I could just import:

    import "github.com/lmbarros/go_markydown"

(you can also leave the go_ off if this will be the only thing called
markydown on your GitHub account)

if len(p.input) == 0 {
return false
}
// Try parsing each of the "special" paragraph types.
if p.parseHeading() {
return true
}
if p.parseBulletedParagraph() {
return true
}

some people prefer to write long chains of I




-- 
Sam Whited
pub 4096R/54083AE104EA7AD3

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to