# Syntactic sugar to encourage use of named arguments

**URL:** <https://discuss.python.org/t/syntactic-sugar-to-encourage-use-of-named-arguments/36217>\
**Category:** Ideas\
**Created:** [October 14, 2023, 5:38pm UTC](https://discuss.python.org/t/syntactic-sugar-to-encourage-use-of-named-arguments/36217 "2023-10-14T17:38:31Z")\
**Posts on this page:** 1\
**Showing post:** 94

<div class="post-metadata">

**Author:** ![sirosen](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/sirosen/32/8478_2.png) [@sirosen](https://discuss.python.org/u/sirosen)\
**Post date:** [October 30, 2023, 6:49pm UTC](https://discuss.python.org/t/syntactic-sugar-to-encourage-use-of-named-arguments/36217/94 "2023-10-30T18:49:11Z")

</div>

@tmk, I’m not 100% clear which thing you’re looking for in an example, but I think you mean “variable lifting” in Ruby? Let me know if I’ve misunderstood.  
I don’t have any FOSS projects, unfortunately, but I’ll provide a sanitized example from my closed-source work.

> **example from a real (closed source) Ruby codebase**
>
> This is part of menu building for a static site generator.  
> I’ve tried to remove any $COMPANY-specific details.  
> Feel free to DM critiques of my Ruby to me, but not in this already-long thread.
> 
> ```ruby
> def render_menu(
> item_descriptors, depth: 0, maxdepth: 1, collapsible: false
> )
> # render each item in the menu
> rendered_items = item_descriptors.map do |item_desc|
> # do we have subsections to render or not? (only if there is depth left)
> has_subsections = (
> (maxdepth - depth).positive? &&
> item_desc[:subsections] && item_desc[:subsections].length.positive?
> )
> 
> # create the link to the current item
> rendered_item = link_to(
> item_desc[:item][:short_title], relative_path_to(item_desc[:item])
> )           
>                 
> # combine with the subsections if there are any to render
> if has_subsections
> rendered_item = html_tag(
> 'div',
> %W[   
> #{rendered_item} 
> <button class="caret"
> aria-label="expand/collapse #{item_desc[:item][:short_title]} submenu">
> <span class="caret"></span>
> </button>
> ].join(' '),
> { 
> class: 'sidebar-heading',
> role: 'navigation',
> 'aria-haspopup': 'true',
> 'aria-expanded': 'false'
> }
> )
> rendered_item += render_menu(
> item_desc[:subsections],
> depth: depth + 1,
> maxdepth:,
> collapsible: true
> )
> 
> html_tag('li', rendered_item, class: 'sidebar-submenu')
> else
> html_tag('li', rendered_item, class: 'sidebar-leaf-item')
> end
> end.join
>     
> tree_class = "sidebar-tree sidebar-tree-l#{depth}" + (
> collapsible ? ' sidebar-tree-collapsible' : ''
> )
> html_tag('ul', rendered_items, class: tree_class)
> end
> 
> ```

Note how that use of `maxdepth:,` does very little to simplify the code or meaningfully improve readability.  
My take is that the feature isn’t really bad, but I’m not seeing a lot of benefit from it and I _hate_ that Rubocop more or less strong-arms me into writing it this way.

I’m trying to tread a fine line and avoid spreading any irrational fear about the feature while still giving voice to my misgivings.  
If the goal of the feature is to improve readability, then it needs to decide whether or not

```auto
render_menu(
    item_desc.subsections,
    depth=depth + 1,
    maxdepth=,
    collapsible=True
)

```

is a readability improvement.

I would appreciate a few examples, in any PEP for this, which show when it is _not_ appropriate. I think that would be enough to guide people away from overzealously trying to enforce this usage on everyone.

---

_[View the full topic](https://discuss.python.org/t/syntactic-sugar-to-encourage-use-of-named-arguments/36217)._
