---
title: "Naming init parameters"
slug: naming-init-parameters
section: tech
date: 2017-05-27T23:46:00.000Z
canonical: https://roland.leth.ro/blog/tech/naming-init-parameters
---

I used to name them by the type of the parameters passed in, for example:

```swift
let dictionary = ["name": "Sneakers", "price": "40"]
let product = Product(dictionary: dictionary)
let viewModel = ProductViewModel(product: product)
```

But lately, I've been using a more Swifty approach, by having an external name of `from` or `with`:

```swift
let dictionary = ["name": "Sneakers", "price": "40"]
let product = Product(from: dictionary)
let viewModel = ProductViewModel(with: product)
```

How do I pick between the two? I go with the following approach:

  * if the object relies entirely on the parameter, I use `from`
  * if the object has other properties, independent on the parameter, I use `with`

In our example above, the `product` is a model, and models are usually created entirely from a dictionary (a JSON), while the `viewModel` might have other properties, like `numberOfSections` & `numberOfRows` for a `tableView` or `buttonTitle` - "Buy" or "Sold Out", for example.

Is the difference too subtle and not worth stressing over? Or does it slightly improve the semantic? Let me know what you think [@roland.leth.ro](https://bsky.app/profile/roland.leth.ro).