Skip to content

Commit 8a94fb0

Browse files
feat: 'Default arguments' -> 'Default parameters' (#4833)
* 'Default arguments' -> 'Parameters with default values'. And lambda is not a parameter but an argument Summarization of the team discussion: - It's definitely ok to call it "optional parameters", but unfortunately it's not a wide-spread term - It's ok to say it in full "parameters with default values" - It's ok to say "default value" (if it's clear from the context) - "default parameters" and "default arguments" are slightly problematic and it's better to avoid them Discussion link: https://jetbrains.slack.com/archives/C06E082M6/p1746713347805569 The commit fixes two problems: 1. Avoid using "default arguments" and "default parameters" 2. Lambda is not a parameter. It's an expression, and it's an argument that corresponds to a parameter with functional type. * Update anchors: #default-arguments -> #parameters-with-default-values I missed some anchors in the previous commit * Update all the remaining 'default arguments' See the commit before the previous for motivation * chore: add new term in compiler's guide mention * update: replace mentions of optional parameters for consistency * update: replace with parameters with default values * chore: fix typo --------- Co-authored-by: alepedroza <[email protected]>
1 parent aa31720 commit 8a94fb0

15 files changed

+37
-35
lines changed

docs/topics/coding-conventions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ class Point(val x: Double, val y: Double) {
11281128
```
11291129

11301130
If you have an object with multiple overloaded constructors that don't call different superclass constructors and
1131-
can't be reduced to a single constructor with default argument values, prefer to replace the overloaded constructors with
1131+
can't be reduced to a single constructor including parameters with default values, prefer to replace the overloaded constructors with
11321132
factory functions.
11331133

11341134
### Platform types

docs/topics/collection-parts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fun main() {
120120
```
121121
{kotlin-runnable="true" kotlin-min-compiler-version="1.3"}
122122

123-
`windowed()` provides more flexibility with optional parameters:
123+
`windowed()` provides more flexibility regarding parameters with default values:
124124

125125
* `step` defines a distance between first elements of two adjacent windows. By default the value is 1, so the result contains windows starting from all elements. If you increase the step to 2, you will receive only windows starting from odd elements: first, third, and so on.
126126
* `partialWindows` includes windows of smaller sizes that start from the elements at the end of the collection. For example, if you request windows of three elements, you can't build them for the last two elements. Enabling `partialWindows` in this case includes two more lists of sizes 2 and 1.

docs/topics/collection-transformations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ strings: [`joinToString()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.
244244
`joinToString()` builds a single `String` from the collection elements based on the provided arguments.
245245
`joinTo()` does the same but appends the result to the given [`Appendable`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-appendable/index.html) object.
246246

247-
When called with the default arguments, the functions return the result similar to calling `toString()` on the collection:
248-
a `String` of elements' string representations separated by commas with spaces.
247+
When called with the parameters' default values, the functions return the result similar to calling `toString()` on the collection:
248+
a `String` of elements' string representations separated by commas with spaces.
249249

250250
```kotlin
251251

docs/topics/compatibility-guides/compatibility-guide-22.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,20 @@ perspective (for example, from Java) is out of the scope of this document.
190190
>
191191
> - 2.2.0: report an error when accessing private types or members from non-private inline functions
192192
193-
### Forbid non-local returns in default argument lambdas
193+
### Forbid non-local returns in lambdas used as parameter's default value
194194

195195
> **Issue**: [KTLC-286](https://youtrack.jetbrains.com/issue/KTLC-286)
196196
>
197197
> **Component**: Core language
198198
>
199199
> **Incompatible change type**: source
200200
>
201-
> **Short summary**: Non-local return statements are no longer allowed in lambdas used as default arguments.
202-
> This pattern previously compiled but led to runtime crashes. To migrate, rewrite the lambda to avoid non-local returns or move the logic outside the default argument.
201+
> **Short summary**: Non-local return statements are no longer allowed in lambdas used as parameter's default value.
202+
> This pattern previously compiled but led to runtime crashes. To migrate, rewrite the lambda to avoid non-local returns or move the logic outside the default value.
203203
>
204204
> **Deprecation cycle**:
205205
>
206-
> - 2.2.0: report an error for non-local returns in lambdas used as default argument values
206+
> - 2.2.0: report an error for non-local returns in lambdas used as parameter's default value
207207
208208
## Standard library
209209

docs/topics/exceptions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,11 @@ creating a hierarchy of exceptions can help making the code clearer and more spe
459459
You can achieve this by using an [abstract class](classes.md#abstract-classes) or a
460460
[sealed class](sealed-classes.md#constructors) as a base for common exception features and creating specific
461461
subclasses for detailed exception types.
462-
Additionally, custom exceptions with optional parameters offer flexibility, allowing initialization with varied messages,
462+
Additionally, custom exceptions including parameters with default values offer flexibility, allowing initialization with varied messages,
463463
which enables more granular error handling.
464464
465465
Let's look at an example using the sealed class `AccountException` as the base for an exception hierarchy,
466-
and class `APIKeyExpiredException`, a subclass, which showcases the use of optional parameters for improved exception detail:
466+
and class `APIKeyExpiredException`, a subclass, which showcases the use of parameters with default values for improved exception detail:
467467
468468
```kotlin
469469
//sampleStart

docs/topics/functions.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ fun powerOf(
4040
) { /*...*/ }
4141
```
4242

43-
### Default arguments
43+
### Parameters with default values
4444

45-
Function parameters can have default values, which are used when you skip the corresponding argument. This reduces the number
46-
of overloads:
45+
Function parameters can have default values, which are used when you skip the corresponding argument.
46+
This reduces the number of overloads:
4747

4848
```kotlin
4949
fun read(
@@ -53,6 +53,8 @@ fun read(
5353
) { /*...*/ }
5454
```
5555

56+
Such parameters are also referred to as _optional parameters_.
57+
5658
A default value is set by appending `=` to the type.
5759

5860
Overriding methods always use the base method's default parameter values.
@@ -68,7 +70,7 @@ class B : A() {
6870
}
6971
```
7072

71-
If a default parameter precedes a parameter with no default value, the default value can only be used by calling
73+
If a parameter with default value precedes a parameter with no default value, the default value can only be used by calling
7274
the function with [named arguments](#named-arguments):
7375

7476
```kotlin
@@ -80,8 +82,8 @@ fun foo(
8082
foo(baz = 1) // The default value bar = 0 is used
8183
```
8284

83-
If the last argument after default parameters is a [lambda](lambdas.md#lambda-expression-syntax),
84-
you can pass it either as a named argument or [outside the parentheses](lambdas.md#passing-trailing-lambdas):
85+
If the last parameter after all parameters with default values has a functional type,
86+
then you can pass the corresponding [lambda](lambdas.md#lambda-expression-syntax) argument either as a named argument or [outside the parentheses](lambdas.md#passing-trailing-lambdas):
8587

8688
```kotlin
8789
fun foo(
@@ -247,7 +249,7 @@ for the call). Infix functions must meet the following requirements:
247249
* They must be member functions or [extension functions](extensions.md).
248250
* They must have a single parameter.
249251
* The parameter must not [accept variable number of arguments](#variable-number-of-arguments-varargs) and must have
250-
no [default value](#default-arguments).
252+
no [default value](#parameters-with-default-values).
251253

252254
```kotlin
253255
infix fun Int.shl(x: Int): Int { ... }

docs/topics/gsoc-2023.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ but the support for code that uses composition instead of inheritance has yet to
138138

139139
The main problem of working with code that heavily uses composition is parameter forwarding.
140140
In particular:
141-
* The IDE doesn't suggest completing parameter declarations that can be forwarded as arguments to other functions that currently use default arguments.
141+
* The IDE doesn't suggest completing parameter declarations that can be forwarded as arguments to other functions that currently use default parameter values.
142142
* The IDE doesn't rename the chain of forwarded parameters.
143143
* The IDE doesn't provide any quick-fixes that fill in all the required arguments with parameters that can be forwarded.
144144

docs/topics/js/js-interop.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ external class MyClass {
9292
}
9393
```
9494

95-
### Declare optional parameters
95+
### Declare parameters with default values
9696

97-
If you are writing an external declaration for a JavaScript function which has an optional parameter, use `definedExternally`.
97+
If you are writing an external declaration for a JavaScript function which has a parameter with a default value, use `definedExternally`.
9898
This delegates the generation of the default values to the JavaScript function itself:
9999

100100
```kotlin
@@ -133,7 +133,7 @@ class Bar : Foo() {
133133
There are some limitations:
134134

135135
- When a function of an external base class is overloaded by signature, you can't override it in a derived class.
136-
- You can't override a function with default arguments.
136+
- You can't override a function including parameters with default values.
137137
- Non-external classes can't be extended by external classes.
138138

139139
### external interfaces

docs/topics/jvm/comparison-to-java.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Kotlin fixes a series of issues that Java suffers from:
4545
* [Data classes](data-classes.md)
4646
* [Coroutines](coroutines-overview.md)
4747
* [Top-level functions](functions.md)
48-
* [Default arguments](functions.md#default-arguments)
48+
* [Parameters with default values](functions.md#parameters-with-default-values)
4949
* [Named parameters](functions.md#named-arguments)
5050
* [Infix functions](functions.md#infix-notation)
5151
* [Expect and actual declarations](https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-expect-actual.html)

docs/topics/jvm/java-to-kotlin-nullability-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ findOrder()?.customer?.let(::processCustomer)
216216

217217
## Default values instead of null
218218

219-
Checking for `null` is often used in combination with [setting the default value](functions.md#default-arguments)
219+
Checking for `null` is often used in combination with [setting the default value](functions.md#parameters-with-default-values)
220220
in case the null check is successful.
221221

222222
The Java code with a null check:

0 commit comments

Comments
 (0)