News for hackers. Stuff that matters.
Re:Show HN: email - Send emails easily in Go by tshadwell on Tuesday January 07, 2014 @02:22PM (#7019235)
Interesting choice of NewEmail() over the more idiomatic email.New().
Re:Show HN: email - Send emails easily in Go by jwcrux on Tuesday January 07, 2014 @02:30PM (#7019300)
Good point - when developing the package, I was referencing these [1][2] documents which showed the use of NewObject() instead of New(). I figured since I provide more than one possible struct (both Email and Attachment), the use of NewEmail would provide consistency.

However, now that you mention it, I suppose it wouldn't have hurt, and the meaning would have been fairly clear. Oh well - live and learn, at this point, I'm doing my best not to break backwards compatibility if I don't have to.

Thanks for the heads up!

[1] http://golang.org/doc/effective_go.html#composite_literals

[2] https://sites.google.com/site/gopatterns/object-oriented/con...

Re:Show HN: email - Send emails easily in Go by scott_s on Tuesday January 07, 2014 @07:20PM (#7020949)
Stuart Feldman, from "The Art of Unix Programming", on why makefiles must use tabs:

"Why the tab in column 1? Yacc was new, Lex was brand new. I hadn't tried either, so I figured this would be a good excuse to learn. After getting myself snarled up with my first stab at Lex, I just did something simple with the pattern newline-tab. It worked, it stayed. And then a few weeks later I had a user population of about a dozen, most of them friends, and I didn't want to screw up my embedded base. The rest, sadly, is history."

Re:Show HN: email - Send emails easily in Go by DrJokepu on Tuesday January 07, 2014 @02:51PM (#7019438)
If your package exports a single type only, New is more appropriate, if it exports multiple types, you should use NewObject:

http://golang.org/doc/effective_go.html#names

Re:Show HN: email - Send emails easily in Go by mseepgood on Tuesday January 07, 2014 @05:41PM (#7020514)
Many packages have a dominant type and a couple of satellite types. If the package name is the same as or similar to the name of the dominant type, 'New' can be appropriate as well.
Re:Show HN: email - Send emails easily in Go by DrJokepu on Tuesday January 07, 2014 @06:07PM (#7020644)
Right. As long it’s super obvious which type New creates, it’s perfectly fine.
Re:Show HN: email - Send emails easily in Go by dkuntz2 on Tuesday January 07, 2014 @02:32PM (#7019307)
Like ihsw said, in Go you probably should leave it as `NewEmail` because `New` is ambiguous.
Re:Show HN: email - Send emails easily in Go by ihsw on Tuesday January 07, 2014 @02:30PM (#7019296)
In actuality it would be `email.NewEmail()` -- the lack of namespace specificity is due to the code examples already being part of the package. The issue with a simple `New()` 'constructor' is that there is ambiguity as to what struct it's creating.
Re:Show HN: email - Send emails easily in Go by staunch on Tuesday January 07, 2014 @02:53PM (#7019452)

   package main
   
   import (
       "log"
       "net/smtp"
       "github.com/jordan-wright/email"
   )
   
   func main() {
       e := email.NewEmail()
       e.From = "Jordan Wright <[email protected]>"
       e.To = []string{"[email protected]"}
       e.Bcc = []string{"[email protected]"}
       e.Cc = []string{"[email protected]"}
       e.Subject = "Awesome Subject"
       e.Text = "Text Body is, of course, supported!"
       e.HTML = "<h1>Fancy HTML is supported, too!</h1>"
       err := e.Send("smtp.gmail.com:587",
           smtp.PlainAuth("", "[email protected]", "pw", "smtp.gmail.com"))
       if err != nil {
           log.Fatal(err)
       }
   }
Re:Show HN: email - Send emails easily in Go by mratzloff on Tuesday January 07, 2014 @02:58PM (#7019499)
There are dozens of instances of New() in the standard library.
Re:Show HN: email - Send emails easily in Go by dkuntz2 on Tuesday January 07, 2014 @02:28PM (#7019282)
In Go isn't `email.NewEmail()` more idiomatic?

To be fair, you could write:

e = &email.Email{ [fields and values] }

The only thing NewEmail does is give you a pointer to an Email.

Re:Show HN: email - Send emails easily in Go by ihsw on Tuesday January 07, 2014 @02:31PM (#7019304)
Re:Show HN: email - Send emails easily in Go by noselasd on Tuesday January 07, 2014 @04:26PM (#7020066)
There's a lot of NewXXX too. The convention is if a package exports only one single type, call it New(...), otherwise call it NewXXX(...)