Code Monkey home page Code Monkey logo

Comments (12)

ozra avatar ozra commented on July 22, 2024

Named arguments has been considerably improved, but will not be able to be required. Now follow similar rules to Python.

from onyx-lang.

Sod-Almighty avatar Sod-Almighty commented on July 22, 2024

Making named arguments mandatory is a Very Good Idea™. Why are we dropping this?

from onyx-lang.

ozra avatar ozra commented on July 22, 2024

Motivation?

from onyx-lang.

Sod-Almighty avatar Sod-Almighty commented on July 22, 2024

Same motivation as mandatory unnamed arguments - the necessity of which surely you accept? - except with the advantage of explicit naming. It's a common idiom in Obj-C and Swift, and even Ruby supports this now.

Indeed, an argument could be made for the abolition of unnamed arguments completely. They lead to sloppy code.

I put it to you that keyword parameters are the future. Keyword parameters are to implicit parameters, what typed variables are to void pointers.

from onyx-lang.

ozra avatar ozra commented on July 22, 2024

I would say that any function that requires named parameters to keep track of what their purpose is, is a badly designed function ;-)
Now, naturally these bad boys of functions are an unfortunate practical necessity, much of the time, in the imperative world. But I still see no reason to force a user to pass arguments via keyword names. Good programming practices should be promoted, but not forced.

I'd like to strive towards:
Less things forced on the user.
More constructs available for self chosen enforcement.

I'm considering the essence of your want, thinking out of above mentioned perspective. With the "code modes" concept (being able to demand different levels of strictness on code in different lexical scopes) - it could simply be added as a hardening-mode: '!require-named-argument-calls - or something similarly named.

from onyx-lang.

Sod-Almighty avatar Sod-Almighty commented on July 22, 2024

Provided there is a mechanism whereby this can be mandated, that's fine.

Although quite often it can make sense to have the first argument anonymous, while subsequent arguments are explicitly named. This is a common idiom in Objective-C and Swift. We should support that.

from onyx-lang.

ozra avatar ozra commented on July 22, 2024

I'll take the liberty to expand further on this track.
The suggested method, in tandem with "suggestion-decorations" in the function def params is also an alternative.

Like the existing idea of:

type Foo
   foo() -> 'please-dont-override-me
      do-shit()

Like "final", but, once again, just a recommendation. The user can then via directives choose to "require 'redef modifier for all overridden", or "for all overrides where the original is marked with the 'dont-override, or "no explicitness required at all - just override at the drop of a hat" (that is: no demand directives are used).

Note: "please-dont-override-me" is naturally not what that pragma will be called ;-)

So for this case, something like:

-- "my-fun.ox"
my-fun(arg1, arg2!, arg3! = 47) ->   -- in this example: `!` means "suggested mandatory"
   do-stuff

-- "my-app.ox"
require "my-fun"
'!require-mandatory-keyword-args

my-fun 1, 2, 3   -- Error! We chose to promise to follow the suggestions as mandatory 

Another option is, provided the mentioned "first-arg is anonymous, rest is not"-convention is common enough, to have a specific directive for that, without having to decorate "recommendations" for all args except the first on all funcs. That might be too stiff a rule to work in practise though?

from onyx-lang.

Sod-Almighty avatar Sod-Almighty commented on July 22, 2024

No, mandating all functions to follow this rule is a bit too restrictive. But allowing the functions to specify their own rules is fine.

! suffix implies "mandatory parameter", not necessarily "mandatory keyword parameter". Perhaps my-fun(arg1, "arg2", "arg3" = 47)?

Remind me....why is a : suffix not possible here?

from onyx-lang.

ozra avatar ozra commented on July 22, 2024

: suffix? Come again?

If it helps, here is the current function def syntax - shown with the new return-type syntax such as I'm currently re-coding it though. Would've been done today if it wasn't for the track and fields action in the forest:

func-name(optional-ext-par-name => internal-name OptionalType = optional-value) -> OptionalReturnType. For example:

foo(from => from-date Date, to => to-date Date) -> Span
   do-some-shit-and-produce-a-span(from-date, to-date)

my-span = foo from: some-date, to: some-other-date

from onyx-lang.

Sod-Almighty avatar Sod-Almighty commented on July 22, 2024

Ruby uses the : suffix for keyword params:

def my_fn(arg1:, arg2:)
end

my_fn arg1: 10, arg2: 20

from onyx-lang.

ozra avatar ozra commented on July 22, 2024

Aha, no that's not needed. You can keyword any arg you want.

from onyx-lang.

ozra avatar ozra commented on July 22, 2024

You don't need to specify an external name, if that wasn't clear. This is all ok too:

foo(x, y) -> say "{x} to {y}"
foo y: "code", x: "love"  --> "love to code"

from onyx-lang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.