Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #21159

Re: (golf-ish) Conditional object property access

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <7836422.gBDQCprLM3@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Organization PointedEars Software (PES)
Date Tue, 03 Sep 2013 01:59:17 +0200
User-Agent KNode/4.10.5
Content-Transfer-Encoding 8Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: (golf-ish) Conditional object property access
Newsgroups comp.lang.javascript
References <l02s3s$fdt$1@reader1.panix.com> <0.c54068976de565cd12fc.20130902215206BST.877gezuetl.fsf@bsb.me.uk> <1513771.HS4XPLjgls@PointedEars.de> <0.cf0106c707f704dac5bd.20130902231902BST.87zjruuasp.fsf@bsb.me.uk>
MIME-Version 1.0
Lines 59
NNTP-Posting-Date 03 Sep 2013 01:59:19 CEST
NNTP-Posting-Host 47227e13.newsspool3.arcor-online.net
X-Trace DXC=khl>D?UNo3eIkjb;<8iR=aMcF=Q^Z^V3h4Fo<]lROoRa8kF<OcfhCOkVji1_n_VeiiDZm8W4\YJNlb@mF9jNikdeeCNKDhNBK@jJ]\[eoFi32`
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:21159

Show key headers only | View raw


Ben Bacarisse wrote:

> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:
>> Ben Bacarisse wrote:
>>> If HAS returns o.p when o.hasOwnProperty('p'), then you can avoid the
>>> conditional
>>> 
>>>   HAS(o, 'p') || <EXPR>
>>
>> Incorrect.  There is a difference between an object having a property and
>> converting the result of a property access to Boolean.  Assuming you
>> meant
>>
>>   function HAS (o, p)
>>   {
>>     if (o.hasOwnProperty(p)) return o[p];
>>   }
>>
>> (where “HAS” is a very unwise identifier), if the value of o[p] was a
>> false- value, the result of
>>
>>   HAS(o, 'p') || <EXPR>
>>
>> would be
>>
>>   <EXPR>
> 
> Yes, good point.  I've used something similar, but in situations where
> this problem would be unlikely.  I was too hasty, though I suppose it's
> possible that || works in all the OP's use cases.

I do not think there is a use-case here.  That is the very nature of code-
golfing, because it is more play than work: trying to find the shortest 
equivalent expression, however unreadable, to solve a *theoretical* problem.  
You would never used golfed code in production: it is probably inefficient, 
likely error-prone, and definitely hard to maintain.
 
>>> Anything that uses functions to wrap EXPR for delayed execution suffers
>>> from the fact the ECMAScript uses such a long keyword, and that the
>>> syntax requires empty parentheses.  (I take it that one of the rules of
>>> this golf game is that the expression should be short.)
>>
>> Harmony (ECMAScript Edition 6) is going to fix that with foo(bar => baz):
>>
>> <http://wiki.ecmascript.org/doku.php?id=harmony:arrow_function_syntax>
> 
> Nice.  The return is no longer needed in simple cases too.  It's always
> seemed to me that the early designers never expected the wide use that
> function expressions would get.

ISTM that this particular syntax for lambda expressions was borrowed from 
C#, which in turn might have shortened that of Python.  I learned it when I 
first used LINQ extension methods about a year ago.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

(golf-ish) Conditional object property access kj <no.email@please.post> - 2013-09-02 20:23 +0000
  Re: (golf-ish) Conditional object property access Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-09-02 21:52 +0100
    Re: (golf-ish) Conditional object property access Stefan Weiss <krewecherl@gmail.com> - 2013-09-02 23:11 +0200
    Re: (golf-ish) Conditional object property access Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-03 00:03 +0200
      Re: (golf-ish) Conditional object property access Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-09-02 23:19 +0100
        Re: (golf-ish) Conditional object property access Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-03 01:59 +0200
  Re: (golf-ish) Conditional object property access Stefan Weiss <krewecherl@gmail.com> - 2013-09-02 23:10 +0200

csiph-web