# Choosing between with() and run()

DevFeed: [Choosing between with() and run()](<https://devfeed.tech/articles/choosing-between-with-and-run-25032.md>)

Original publisher: [Read original article](<https://typealias.com/guides/choosing-between-with-and-run/>)

Author: author@typealias.com (Dave Leeds)

Published: 2017-09-14T01:23:30Z

Content type: tutorial

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Library](<https://devfeed.tech/topics/library.md>), [Code](<https://devfeed.tech/topics/code.md>), [context](<https://devfeed.tech/topics/context.md>)

Tags: [comparison](<https://devfeed.tech/tags/comparison.md>), [extension-function](<https://devfeed.tech/tags/extension-function.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [readability](<https://devfeed.tech/tags/readability.md>), [run](<https://devfeed.tech/tags/run.md>), [safe-call-operator](<https://devfeed.tech/tags/safe-call-operator.md>), [scope-functions](<https://devfeed.tech/tags/scope-functions.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>)

## AI overview

This Kotlin tutorial compares with() and run(), explaining that they are nearly identical in compiled behavior and differ mainly in syntax. It highlights the extension-function advantage of safe-call handling for nullable receivers and discusses readability trade-offs.

## Source excerpt

In Kotlin's standard library, the Standard.kt file contains a number of scope functions that put a receiver object into a new scope as either this or as an argument (e.g., it). The with() function tends to be a bit of an outlier. The others are all extension functions, so they're invoked on an object. with(), on the other hand, takes its receiver (the object that it's operating upon) as an argument.