lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

get_property vs internal_get_property (was: issue 127860043)


From: Janek Warchoł
Subject: get_property vs internal_get_property (was: issue 127860043)
Date: Mon, 18 Aug 2014 08:39:50 +0200

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?

Most of my early exposure to Lily's C++ code was with
Self_alignment_interface, which for some reason used
internal_get_property and which imprinted on myself the idea of using
internal_get_property.  This was further strengthened by the fact that
get_property is defined as a macro and thus doesn't show up in IDE as
a method of Grob class.  The more Lily code i read, the more i see
that get_property is used almost everywhere else...  Why not define
get_property as a member of the Grob class, too?

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?

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/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]