[ 
https://issues.apache.org/jira/browse/THRIFT-2232?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13961968#comment-13961968
 ] 

Aleksey Pesternikov commented on THRIFT-2232:
---------------------------------------------

I started changing my existing code to reflect this change. Some thoughts on 
the way:
- optional with defaults are broken (THRIFT-2451)
- inlined fields are much easier to deal with and far more optimal in terms of 
producing memory garbage.
- code using old "optional field is unset when it has default value" semantics 
feels like a natural fit for go.
this is a part of my code:
thrift:
struct log {
  [...]
  42: optional string referrer
  43: optional string user_agent
  100: optional bool is_admin = false
}
old_code(req *http.Request) {
  l.Referrer = req.Referrer()
  l.UserAgent = req.UserAgent()
  l.IsAdmin = calculateAdminStatus(req)
}
equivalent_new_code(req *http.Request) {
        if s := req.Referer(); s != "" {
                l.Referer = &s
        }
        if s := req.UserAgent(); s != "" {
                l.UserAgent = &s
        }
        if calculateAdminStatus(req) {
                l.IsAdmin = thrift.BoolPtr(true)
        }
}
Easy to see that the old way is waaay more readable.
I'm even ready to deal with some restrictions of this model - like it is 
impossible to have non-zero default for non-comparable types like maps.
So, going back to the description of the bug: if you replace "magic values" 
with "default values" it is not "obviously broken" anymore. I'm about to 
implement the old mapping. It will not be turned on by default. Instead, it 
will be controlled by option passed to generator.
Any thoughts?


> IsSet* broken in Go
> -------------------
>
>                 Key: THRIFT-2232
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2232
>             Project: Thrift
>          Issue Type: Bug
>          Components: Go - Compiler
>            Reporter: Ben Sigelman
>            Assignee: Jens Geyer
>              Labels: isset
>             Fix For: 0.9.2
>
>         Attachments: THRIFT-2322_optional_set_assignment_issue.patch, 
> THRIFT-2322_regenerated_serializer_testfile.patch, 
> thrift-2232-golang-optional-fields-fix.patch
>
>
> The various generated IsSetXYZ() methods just check for magic values of their 
> respective fields. This is obviously broken, and also diverges from the 
> implementation in other languages.
> I am willing and able to fix this myself, but I don't want to start on any 
> impl until we can decide on an approach.
> At this point, though, optional fields in Go are basically useless if one's 
> application makes use of the magic "absence" value.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to