38 lines
1.3 KiB
Markdown
38 lines
1.3 KiB
Markdown
|
---
|
||
|
title: Why I use long parameter names in scripts
|
||
|
date: 2024-05-23
|
||
|
permalink: daily/2024/05/23/why-i-use-long-parameter-names-in-scripts
|
||
|
tags:
|
||
|
- software-development
|
||
|
- bash
|
||
|
- zsh
|
||
|
- linux
|
||
|
cta: ~
|
||
|
snippet: |
|
||
|
Why I use long parameter names in scripts, such as `--force` instead of `-f`.
|
||
|
---
|
||
|
|
||
|
The other day, [I posted about a script I'd written][0] that found the longest commit message in a repository.
|
||
|
|
||
|
As I couldn't find a native way to do this with Git, the script loops over each commit in the repository, calculates its length and stores the length and commit SHA in a file.
|
||
|
|
||
|
The lines in the file are sorted so the longest commit is first.
|
||
|
|
||
|
Whilst I commonly use short parameters, such as `git add -p` when typing commands, in scripts, I prefer to use the equivalent longer parameters, where possible.
|
||
|
|
||
|
For example, in the script, I execute this command to sort the lines:
|
||
|
|
||
|
```bash
|
||
|
sort "${result_file}" --reverse --numeric-sort --output "${result_file}"
|
||
|
```
|
||
|
|
||
|
This could be re-written as:
|
||
|
|
||
|
```bash
|
||
|
sort "${result_file}" -rn -o "${result_file}"
|
||
|
```
|
||
|
|
||
|
Whilst the original is more verbose and longer to type, I prefer its verbosity which makes it easier for me or others to read and understand in the future.
|
||
|
|
||
|
[0]: {{site.url}}/daily/2024/05/21/which-commit-has-the-largest-message
|