On Friday 13 of May 2016 08:55:35 David Davis wrote:
> The fact that we’ve already uncovered one problem seems to me like it is a
> problem.

That's fair, I just haven't encountered it myself yet.

> Also, I’m interested to know why you think modifying string
> constants is concerning but not hash or array constants.

I said more concerning :-) somehow I look at strings as simple data type, 
arrays, hashes, structs, sets etc are complex composes of multiple types. But 
I understand that there are no primitives, just objects, in Ruby so as long as 
object is mutable, it might change even if set as constant.

Anyway, seems no one else has objections and I don't have strong opinion, so 
I'll get used to freezing :-)

--
Marek

> 
> 
> David
> 
> On Fri, May 13, 2016 at 3:54 AM, Marek Hulán <[email protected]> wrote:
> > Hello
> > 
> > I have mixed feelings about this. I understand the confusion but I don't
> > think
> > it's too problematic. Constants in Ruby are not really constants anyway.
> > You
> > can redefine them (getting just warning) unless you're in instance method.
> > I
> > don't think majority of libraries would follow this cop suggestions so to
> > remain consistent I'd keep this as is.
> > 
> > I don't have strong opinion on this so If I'm the only one against, feel
> > free
> > to enable it.
> > 
> > OT: note that classes are also just constants pointing to a singleton
> > objects
> > (constant starts with capital letter) and you can change (undefine) them,
> > actually Rails uses this for auto-reloading. With hashes, arrays and other
> > complex objects I find this as a feature rather than bug, what's more
> > concerning to me is this
> > 
> > CONST = 'const'
> > CONST << ' modified'
> > CONST # => 'const modified'
> > 
> > --
> > Marek
> > 
> > On Thursday 12 of May 2016 14:12:56 David Davis wrote:
> > > Yes, the value of the hash changed but it retained the same
> > > address/object_id (which I think was the problem: the code assumed it
> > > was
> > > getting back a value instead of an object reference).
> > > 
> > > This was actually caught in hammer-cli-katello by running the
> > > MutableConstant cop
> > > <http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/MutableConstant>
> > > .
> > 
> > I
> > 
> > > am thinking it might be a good idea to enable it for other repos. At the
> > > very least, it should speed our code up.
> > > 
> > > Thoughts?
> > > 
> > > 
> > > David
> > > 
> > > On Thu, May 12, 2016 at 1:55 PM, Stephen Benjamin <[email protected]>
> > > 
> > > wrote:
> > > > ----- Original Message -----
> > > > 
> > > > > From: "David Davis" <[email protected]>
> > > > > To: [email protected]
> > > > > Sent: Thursday, May 12, 2016 12:44:13 PM
> > > > > Subject: [foreman-dev] Ruby gotcha with constants and hashes
> > > > > 
> > > > > This had me scratching my head for a bit. I’ve seen this problem
> > 
> > before
> > 
> > > > in
> > > > 
> > > > > the Foreman ecosystem so I figured I’d send an email about it.
> > > > > 
> > > > > I was working on a test and got the following output below. It
> > > > > seemed
> > > > 
> > > > weird
> > > > 
> > > > > because it’s a constant and it shouldn’t change (
> > 
> > https://git.io/vrqQO).
> > 
> > > > Can
> > > > 
> > > > > anyone figure out why?
> > > > 
> > > > It didn't "change" depending on how you look at it,  object_id of the
> > 
> > hash
> > 
> > > > stayed
> > > > the same.
> > > > 
> > > > > [1] pry(#<listing repositories>)>
> > > > > HammerCLIKatello::RESOURCE_NAME_MAPPING
> > > > > {
> > > > > 
> > > > >          :system => :content_host,
> > > > >     :
> > > > >     :environment => :lifecycle_environment
> > > > > 
> > > > > }
> > > > > 
> > > > > Here’s a hint: https://git.io/vrq77
> > > > > 
> > > > > David
> > > > > 
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > > > Groups
> > > > > "foreman-dev" group.
> > > > > To unsubscribe from this group and stop receiving emails from it,
> > 
> > send
> > 
> > > > > an
> > > > > email to [email protected].
> > > > > For more options, visit https://groups.google.com/d/optout.
> > > > 
> > > > --
> > > > You received this message because you are subscribed to the Google
> > 
> > Groups
> > 
> > > > "foreman-dev" group.
> > > > To unsubscribe from this group and stop receiving emails from it, send
> > 
> > an
> > 
> > > > email to [email protected].
> > > > For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"foreman-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to