--
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...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Le 3 sept. 2013 00:01, "Dragomir Ivanov" <drago....@gmail.com> a écrit :
>
> I would like very much to name my types without "Type", but then I can't use that name anywhere else:
> type Age uint
> type Name string
> type Person struct {
> Age_ Age /// Can't use Age for the field name
> Name_ Name /// Can't use Name for the field name
> }
>
You can name your fields Age and Type, there's no reason why you couldn't.
Remy.
It's very painful to go through obscure data declarations/manipulation in some projects. For instance where there's a distinction between `CustomerID` and `LegacyCustomerID`, but it's not named the same through the program by the many devs who went through it, and then you're there trying to make sense of which form of `ID` is this raw `int` supposed to be. If you typedef it, the compiler will tell you and you won't be able to mix the two `CustomerID` and `LegacyCustomerID` without being yelled at.
Realize this is an old post.....
On Monday, September 2, 2013 at 3:00:51 PM UTC-6, drago....@gmail.com wrote:Hello,I want to have the following struct:type NameType stringtype AgeType uint32type Name struct {Name NameTypeAge AgeType}Struct fields have to be public. Is this adding "Type" after each typedef inline with the Golang philosophy?Thank you.
Other languages like Delphi solve this problem by going
type TAge int
type TName string
The "T" prefix is short, terse, and doesn't bloat up the code with "TypeThis" or "TypeThat" or "ThisType" or "ThatType
However, this is not a go convention..I'm just mentioning it because other languages have had these same debates and issues, and solved them long ago. (or rather created a subjective flamewar of who prefers what).
I find this sort of stuff confusing:
var Name Name
Compared to:
var Name TName
The "T" terse letter makes you know for sure what is the type and what isn't, as doubling up on name name or age age can look weird, confusing, and you may mix up what is the type and what is the variable if you are used to reading C..
var Name Ooops
How do you know if Ooops is the type, or Name is the type? If you are used to reading C code, you could accidently read it as the type being Name since in C code the type comes first.. not the variable...
explain why?
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
explain why?