Functions with ? and !

Description

Functions should be able to end with ? and ! like Ruby

Activity

Show:

Brad Wood 12 January 2016 at 14:32

Rejected in Dec 9th TAG meeting
http://lang.lucee.org/t/tag-meeting-agenda-december-9th-8pm-utc/265/6

  • In the languages that allow this it is purely a naming convention and function names may contain ? and !. There is nothing special about it.

  • Can interfere with elvis / ternary operators

  • Can already be done with brackets i.e. foo[‘bar?’] = function(){}; foo‘bar?’;

Former user 4 December 2015 at 15:59

I'm in agreement with and - I find the ruby method harder to read and I'm not sure I see a compelling reason to do it short of saving a couple of bytes from the uncompiled source. I'd rather have the readability.

Sean Corfield 16 September 2015 at 20:52
Edited

In Clojure, ? and ! can be part of an identifier and it follows the Ruby convention of foo? returning a boolean and bar! doing something not thread safe so, in principle, I like the idea of expanding the characters that can be part of an identifier. However, the possibility for breaking existing code is too great with ? due to code like foo?bar:baz in my opinion, so I'm with Kai and Adam in being opposed to this.

Kai Koenig 15 September 2015 at 21:14

Looking at this in preparation for TAG meeting 16/09/15.

I don't think is a good idea, for both the reasons provided in the previous comment as well as from a language clarity point of view. I find the syntax just hard to read and we need to have a discussion if this kind of language feature is something we'd want for LuceeLang.

Adam Cameron 13 February 2015 at 02:22

I think this only works in Ruby because the inbuilt methods also employ this syntax, so there's a uniform approach to having boolean-returning methods identified accordingly via the "?" This would make less sense with a CFML-based dialect as it would only be UDFs that have that "convention". And, TBH, I prefer the approach of prefixing the method name with some variation of the verb "to be" (eg: isValid()) or "to have" (hasNext()). That's convention enough.

As for the ! suffix, I don't think Ruby's convention here is very clear. I also think the distinction of "changes the object" or "returns a new object" is best left to a punctuation symbol to differentiate between.

Won't Do

Details

Assignee

Reporter

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Priority

Created 11 February 2015 at 18:25
Updated 12 January 2016 at 14:32
Resolved 12 January 2016 at 14:32

Flag notifications