335 points · by rhim · 2y ago · 156 comments
2. It's amazing how quickly this is going.
3. If you haven't tried fish yet, make sure to do so! It's a really ergonomic shell and overall very pleasant to use, with good defaults (you don't have to customize it, even though you can, for a great experience). I've switched from bash a couple years ago and haven't looked back since.
Bonus: you won't have to google how to write a for loop in bash ever again (which I, writing them rarely, and them being unintuitive enough, had to do every single time)!
Seems to me they're not doing it gradually at all.
> Another thing:
> We plan on not doing any partial-rust release.
> That means we would be doing e.g. fish 4.0 as fully rust and zero C++, and I think, contrary to what we usually do that warrants a beta. (Ordinarily we've stopped doing betas and release candidates because they simply don't get any testing).
> We also still want to do a 3.7.0 in-between release that is still purely C++, so we have a better jumping off point for platforms that can't handle the rust version. It would be 3.6.1 with some neat changes backported.
https://github.com/fish-shell/fish-shell/discussions/10123#d...
They are doing the release all-at-once, but developing gradually. From the original PR[1]:
>This should be thought of as a "port" instead of a "rewrite" because we would not start from scratch; instead we would translate C++ to Rust, incrementally, module by module, in the span of one release. We'll use an FFI so the Rust and C++ bits can talk to each other until C++ is gone, and tests and CI keep passing at every commit.
I think the problem is more like, there are valid files that aren't representable as rust strings?
Incremental index:
for ((i = 0; i < 10; i++)); do echo $i; done
For iterating over an array: foo[0]=a
foo[1]=b
for i in ${foo[@]}; do echo $i; done for i in “${foo[@]}”; do filename="my file.txt"
cat $filename # Incorrect: Tries to 'cat' two files: 'my' and 'file.txt'
cat "$filename" # Correct: Treats 'my file.txt' as one file for i in (seq 10); echo $i; end
or usually written as for i in (seq 10)
echo $i
end
and that is already based on iteration, so for iterating over files, you'll similarly use for f in (ls); echo $f; end
and it works the same for arrays. for i in *
echo $i
end
Fish also has globstar out of the box, so you can do for i in **/*
echo $i
end for i in (seq 10); echo $i; end
directly translated to bash: for i in $(seq 10); do echo $i; doneIt’s that the finer details of the syntax is sufficiently different from other things I do, and I don’t write shell scripts frequently enough to remember it.
repeat 10; echo "repeat me"
If you do need $i you can use a similar construct as bash, but more convenient: for ((i = 0; i < 10; i++)); echo $i
for i in {0..10}; echo $i # {n..m} loops also work in bash
for ((i = 0; i < 10; i++)); { echo $i; echo $i } # Multiple commands
Short loops are hugely helpful in interactive use because it's much less muckery for short one-liners (whether you should use them in scripts is probably a bit more controversial).Also looping over arrays "just works" as you would expect without requiring special incantations:
arr=(a b)
for v in $arr; echo $v
---Whether zsh or fish is better is a matter of taste, and arguably zsh has too many features, but IMHO bash is absolutely stuck as a "1989 ksh clone" (in more ways than one; it uses K&R C all over the place, still has asm hacks to make it run on 1980s versions of Xenix, and things like that).
All of the zsh alternate forms feel far superior to me, in both interactive use and within scripts.
JNRowe notes the many off-by-one translations in other examples and tips hat to arp242
for i in {1..10}Bash array syntax is error prone and hard to read, and the expansion of arrays still depend on the field separator and must fit in the environment.
Most of the time you should just rely on that field separator and do it the simple way:
for i in "$f"; do echo $i; done
Much more obvious and more shell-like. That's how all bash functions process their parameters.Set IFS only if you really need to. But in that case also consider something like xargs where you are not limited by environment, have null terminated fields, and offer parallelism.
Arrays are only useful when you need multidimensionality, at which point you should probably look at using data files and process with other tools such as sed. Or start looking at something like Perl or Python.
f='a b c d e'
for i in "$f"; do echo $i; done
# prints a b c d e
f="a b c 'd e'"
for i in $f; do echo $i; done
# prints
# a
# b
# c
# 'd
# e'
f=(a b c 'd e')
for i in "${f[@]}"; do echo $i; done
# prints
# a
# b
# c
# d eI can generally cobble together python, and it'll be syntactically correct. I just need to check libs.
With shell I need to stop and make sure my semicolons in a for loop are correct.
If you're a heavy user it probably isn't a problem but all the little warts just make it difficult for an occasional user to keep a good enough model in their head.
for i in {1..10}; <<<$i
powershell: foreach ($i in 1..10) { $i }
1..10|%{$_}https://github.com/fish-shell/fish-shell/pull/9512#issuecomm...
That said, I don't use fish and wish them the best
"Too much of a hassle" can mean "too much of a hassle in absolute terms" or "Too much of a hassle compared to what you gain". And porting to c++17 is probably high on the latter...
On the other hand they chose to port to Rust which is likely an even bigger hassle but comes along with a bunch of benefits that make planned future development significantly easier.
Although I don't disagree with this:
> Sorry, you're never ever going to beat "we did it to chase the new shiny" which is the story across the dev world.
I don't think that's the case here. Rust offers more advantages over C++11 than C++17 or C++20 do.
For people who don't want to find the relevant part of the original post, this is it:
> We moved to C++11 in 2016 (some quick calculation shows that's 5 years after the standard was released), and we're still on C++11 because the pain of upgrading is larger than the promises of C++14/17.
So why exactly did they need to rewrite it in Rust?
> In their defense, C++17 adds only some incremental changes. There isn't much to port anyway.
contradicts what they're saying
> and we're still on C++11 because the pain of upgrading is larger than the promises of C++14/17.
I wouldn't understand what "pain" they're suggesting since the "process" of upgrading the codebase to a newer C++ standard is merely done by replacing the -std=c++11 with -std=c++17 in your build flags. In 99% of the cases, you call it a day. In the remaining 1% of the cases, you deal with the warnings the compiler may have issued because of possibly deprecated functions/headers/keywords you may be using in your code. Since there are very few of them (https://isocpp.org/files/papers/p0636r0.html#removed), and are mostly quite a niche or very old legacy, in the worst case it's going to be a matter of a few days it will take you to fix them.
Since C++ (thankfully) pays attention to ABI stability (aka frowned upon "backward compatibility"), the code will still continue to run as before. Tada ... you're done.
P.S. C++17 is more than just an incremental release (https://isocpp.org/files/papers/p0636r0.html) and offers a lot of goodies both in the language spec (e.g. guaranteed copy elision, fold expressions, compile-time if, structured bindings, compile-time lambdas, improved TMP etc.) and library spec (string_view, variant, optional, any, read-write locks, polymorphic allocators, filesystem support etc.).
However, that does _not_ obligate you in any sense to all of the sudden rewrite your whole codebase (!) with new fancy C++17 features - the secret sauce in mature dev environments is that you do it incrementally and where you see fit.
Fish authors decided to take a drastically different route, and that's totally fine, it's their code after all, but in the absence of quantifying the "pain" or the lack of "promises" I call it a FUD.
Another thing I'm very excited about, which has received less attention, is the planned future fish rewrite to use UTF-8 instead of wchar_t (typically UTF-16). UCS2 and UTF-16 have been a plague on software and fortunately Rust makes working with UTF-8 a breeze.
Complicating supporting multiple compilers in one code base, sizeof(wchar_t) is 2 bytes in MSVC (UTF-16) and 4 bytes in gcc (UTF-32).
Fish shell scripting is also extremely pleasant to write, it feels like an ergonomic bash.
There are a few warts, as with any project, but none of them have ever actually ever blocked me from just getting what I wanted done.
fish does a lot out of the box that I needed plugins for in zsh. zsh's plugins are slow, so my shell startup was over three seconds. fish starts way faster, even with plugins.
I highly recommend everyone at least try it for a few days, if only to see what kinds of things you’d always taken granted are actually shell-specific. Worst case: you say “this isn’t for me” and go back to bash/zsh/whatever happy that you’re still using your favorite shell.
I find I stick to fish more because: 1. has more features that I like out of the box. zsh requires oh-my-zsh to get similar features and that's just another thing for me to install every time. 2. Help menu tab completion. Fish has many completions for common shell apps that will display descriptions from the help menu from just hitting tab. 3. Scripting is much better, while you might not use it much now it much now you don't have a hard corner to cut yourself on if you do need it at some point.
Out of the box, effortlessly, I have autocompletion for commands; puts tabs/indentation automatically whenever I start an ad-hoc multiline command inside a for/if statement; a color prompt; etc.
I use fisher for plugins and now have more functions in my dotfiles, but it has far fewer dependencies — like 3 or 4 plugins. When I tried zsh, I immediately added several plugins with oh-my-zsh to feel comfortable.
I'm evaluating zellij instead tmux for the same reason. Some extra batteries included for free, but staying simple enough to keep.
I like it, I would love to run it as my main shell, but I just do too much scripting for my own good to hop on this wagon.
Check it out, it's effective with very little config
function fish_prompt
# Fedora Silverblue workaround
set -l pwd (string replace /var/home /home $PWD)
echo
echo -s (set_color -o cyan)(prompt_pwd -D 3 $pwd) (set_color magenta)(fish_vcs_prompt)
echo -ns (set_color green) "" (set_color normal) " "
endfrom the link :
We have no real idea what the performance of the finished port is going to be. Early results are encouraging, but it is entirely possible this will be ~20% slower in some cases.> Fish also uses threads, for things like the autosuggestion and syntax highlighting, and we would like to have more "threads"/"concurrency"/"run-thing-in-backgroundness" (please insert the correct term here, I have never been good at these things). One large project has been to run multiple fish builtins and functions "at the same time", to enable things like backgrounding functions (ideally without using "subshells" because those are an annoying environment boundary that shows up in surprising places in other shells), and to simply be able to pipe two builtins into each other and have them actually process both ends of the pipe "simultaneously".
> C++ offers few guarantees on what can be accessed from which thread. @ridiculousfish has been trying to crack this for years, and hasn't been confident enough in his solution. We want a tech stack that helps us here, and C++ doesn't.
The initial rewrite may be no faster, or possibly slower as stated, but long-term they'd be able to safely add more concurrency or parallelism that they weren't able to before.
It is easier to make correct program faster than making a fast program correct!Consider the now-classic "Fearless Concurrency" post about Stylo: https://blog.rust-lang.org/2017/11/14/Fearless-Concurrency-I...
Strictly, C++ pretty much has to be no slower than Rust. But it's certainly possible that a regular human might in practice write higher-performing parallel code when using Rust.
Yes, Rust's BC is a great technology, but C++ is not a runaway nuclear fire which contaminates and melts everything around it when it comes to sanity and security.
Yes, Rust allows you to run amok by not allowing it, but you can design a good foundation to your code which prevents tons of problems out of the gate in C++, and this is without using smart-pointers and other things available to you.
I will always take faster code, but that seems like an odd bulletpoint to highlight given the many quality of life improvements fish has to offer.
Those little delays add friction. Not an intolerable amount, sure, but it’s there. While I switched to fish for other reasons, that alone would keep me from going back now.
A lot or most of that wasn't zsh being slow though, but oh-my-zsh calling out to external programs (like git to get powerline info and such) and them being slow.
The nvm init was the worst of it, so now I have an alias for `$NVM_DIR/nvm.sh ] && \. "$NVM_DIR/nvm.sh" && \. $NVM_DIR/bash_completion` I just run manually before using nvm, rather than letting it slow me down half a second or whatever it was every time I open a new terminal.
It's worth poking around if things get slow enough to be a pain. There's a decent chance it's 1-2 things that you don't even care about all that much.
As far as I'm aware, most of the other quality of life improvements can be reproduced in zsh with plugins. This performance bulletpoint makes me want to consider switching back to fish from zsh.
Surely you’re not typing and managing jobs at a pace where C vs C++ vs Rust vs $lang matters… or I’m missing something about what fish is bringing to the table.
It’s already working so well, not sure what there is to gain by porting to Rust. Security? If something can maliciously tamper with fish, it’s probably already on your system or am I missing something?
The downside of this is that you do need to "context switch" a little, especially if you've been using bash/zsh for most of your life. I find it easy to differentiate between when I am using the shell as a user interface and when I'm using bash/sh as an interpreter, but for others that might not be as intuitive.
I've also found that since I've stopped using POSIX compliant shells as my daily driver, I tend to "promote" my scripts to a more general purpose language much sooner than I used to when nearly everything could be done in bash.
Just use your Bash/zsh to run Bash/zsh scripts: `bash script.sh`.
> turned off by it not being POSIX-compliant.
I was like this when I first started using Fish. I spent some time to learn some different syntax to get away from the POSIX-compliance. Overall, I think the saner syntax of Fish is worth the effort. Now I use the terminal much happier.
Besides, 90% of the time I don't need to follow POSIX-compliant. Many scripts or extensions nowadays support Fish.
For enterprise use, I still stick to Bash/zsh. They're the standard.
tl;dr
- string handling
- threading
- cmake issuesWith Go, it would have worked out of the box on all the targets Go can support.
It works in Cygwin right now, it doesn't work on Win32 without a compatibility layer. Personally, I don't think of that as "working on Windows", but I concede that that's somewhat up to interpretation on the "on Windows" part. I'm confident that someone is going to get a MingW build working even if it's not official.
> With Go, it would have worked out of the box on all the targets Go can support.
That's absolutely disingenious. If you choose to only use the Go standard library , sure. But the same is true for Rust and even for C++. If you don't use any platform-specific APIs most languages will work on any target. Fish, however, does use platform-specific APIs and nothing about Go changes that.