what is the difference between required and @required in flutter. What is the difference between them and when do we need to use them?

@required is just an annotation that allows analyzers let you know that you’re missing a named parameter and that’s it. so you can still compile the application and possibly get an exception if this named param was not passed. However sound null-safety was added to dart, and required is now a keyword that needs to … Read more

How can I force calls to some constructors/functions to use named arguments?

In Kotlin 1.0 you can do this by using Nothing from the stdlib. In Kotlin 1.1+ you will get “Forbidden vararg parameter type: Nothing” but you can replicate this pattern by defining your own empty class with a private constructor (like Nothing), and using that as the first varargs parameter. /* requires passing all arguments … Read more

I want to use named parameters in Dart for clarity. How should I handle them?

The meta package provides a @required annotation that is supported by the DartAnalyzer. Flutter uses this a lot and provides @required directly from import ‘package:flutter/foundation.dart’ foo({@required String name}) {…} foo(); // results in static warning @required doesn’t check if the passed value is null or not, only that a value was actually passed on the … Read more

Passing lambda functions as named parameters in C#

Why doesn’t it report the actual error? No, that’s the problem; it is reporting the actual error. Let me explain with a slightly more complicated example. Suppose you have this: class CustomerCollection { public IEnumerable<R> Select<R>(Func<Customer, R> projection) {…} } …. customers.Select( (Customer c)=>c.FristNmae ); OK, what is the error according to the C# specification? … Read more

C++ “Named Parameter Idiom” vs. Boost::Parameter library

Implementing the Named Parameter Idiom is really easy, almost about as easy as using Boost::Parameter, so it kind of boils down to one main point. -Do you already have boost dependencies? If you don’t, Boost::parameter isn’t special enough to merit adding the dependency. Personally I’ve never seen Boost::parameter in production code, 100% of the time … Read more

Are Options and named default arguments like oil and water in a Scala API?

Here’s another solution, partly inspired by Chris’ answer. It also involves a wrapper, but the wrapper is transparent, you only have to define it once, and the user of the API doesn’t need to import any conversions: class Opt[T] private (val option: Option[T]) object Opt { implicit def any2opt[T](t: T): Opt[T] = new Opt(Option(t)) // … Read more