[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: get_property vs internal_get_property (was: issue 127860043)
From: |
Mike Solomon |
Subject: |
Re: get_property vs internal_get_property (was: issue 127860043) |
Date: |
Mon, 18 Aug 2014 10:52:28 +0300 |
On Aug 18, 2014, at 9:39 AM, Janek Warchoł <address@hidden> wrote:
> Hi,
>
> it's time to ask a n00b question and get the elephant (that was
> bothering me for a couple years) out of the room: why do we have - and
> use! - both get_property and internal_get_property? We ought to use
> get_property everywhere, right?
>
...
>
> We are also converting property names from strings to symbols
> everywhere - for example
>
> SCM meta = info.grob ()->internal_get_property (ly_symbol2scm ("meta"));
>
> What's the reason for that? And shouldn't we write all the C++ code
> so that it will automatically do the conversion, like get_property
> does?
>
Entirely reasonable and good idea!
The only slight annoyance is that it is backwards from the logic of almost all
other “internal_X" patterns in LilyPond, where the function X takes Scheme
values and "internal_X" takes C++ values.
Cheers,
MS
> Whew. I feel like an idiot now.
>
> best,
> Janek
>
>
> 2014-08-18 8:09 GMT+02:00 <address@hidden>:
>>
>> https://codereview.appspot.com/127860043/diff/40001/lily/lily-guile.cc
>> File lily/lily-guile.cc (right):
>>
>> https://codereview.appspot.com/127860043/diff/40001/lily/lily-guile.cc#newcode201
>> lily/lily-guile.cc:201: robust_scm2bool (SCM b, bool def)
>> On 2014/08/18 04:57:08, Keith wrote:
>>>
>>> I am not sure, but I think this is a bad idea.
>>> to_boolean() is robust to undefined symbols, returning #f, and a lot
>>
>> of
>>>
>>> define-grobs.scm depends on that convention.
>>> If you add this variant, and people start writing C++ that treats
>>
>> undefined
>>>
>>> symbols as #t, we might get confused.
>>
>>
>> Hmm. Good point. However, to me the situation without robust_scm2bool
>> is also confusing: in fact, i was confused enough to write buggy code :(
>> As far as i can see, the code for getting non-boolean properties
>> follows the convention:
>>
>> Type value = robust_scm2type (grob->get_property("prop-name"), default)
>>
>> When writing code for issue 2245, I have initially tried to use
>> robust_scm2bool - which didn't exist. As i was not aware of to_boolean,
>> i ended up with ly_scm2bool, which turned out to be a bad choice.
>>
>> So, my question is: can we do something to make this more intuitive?
>>
>> What about writing utility functions for getting and converting
>> properties in one step? The current situation is not very elegant - the
>> code sometimes gets so long that it's hard to fit it in 80 chars limit.
>>
>> https://codereview.appspot.com/127860043/
>
> _______________________________________________
> lilypond-devel mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/lilypond-devel