Refactoring a Command Line Shell | Code Roast Part 2

preview_player
Показать описание

Today I'm refactoring a command line shell! This is the second part of the two-part series. Grab your popcorn and get ready to witness some code roasting!

🔖 Chapters:
0:00 Intro
0:32 Hashing
2:36 Clean up the main file
3:30 Simplifying
9:36 Clean up interface class
15:00 Creating a plugin-like mechanism
18:38 Outro

#arjancodes #softwaredesign #python
Рекомендации по теме
Комментарии
Автор

Pedantic change, less of a refactor and more of a UX issue:
Remove the exit animation. There is no cleanup steps being executed; it's just there to be flashy and holds the user hostage for 3 seconds every time they exit the shell.

daephx
Автор

This was a great refactoring session; Loved It!

cetilly
Автор

Instead of having two separate dicts for encoding and decoding funcs why not have a single dict with algo as key and tuple with enc and dec funcs?

nikohegeheiskanen
Автор

One simplification to consider is to drop the keywords "hash", "encode" and "decode" since those are implicit in the algorithms. Then the command would be (for example) md5 <string>. Then you wouldn't need separate logic to handle the three types of commands, they all have the same shape <cmd> <string>.

jeremy
Автор

One change that I would do is migrate from scripts to a module. Currently, that shell app only works if the interpreter is executed from the src folder. To be able to execute the app from anywhere in the system, maybe migrating to modules and using relative imports is a good idea

SkielCast
Автор

The clean version of the code is "oddly satisfying".

Some features to consider adding to this system is a command history, some input/output capability (to avoid the need to copy and paste the various results and to keep track of the algorithms applied) and also some way to perform batch processing.

Isn't there a one-to-one correspondence between the encoding and decoding algorithms? I suppose there is... If so, I think it would be a good idea to have this fact reflected in the data structures, by combining the ENCODING_ALGORITHMS and DECODING_ALGORITHMS dictionaries into a single one.

xnick_uy
Автор

I like it when code is kept to the point such that people can fork and do their thing with it. Nice job! 😄

I'd like to see you code a performant game engine in Mojo. The tradeoff between "clean" design and fast execution could be very interesting 😁😉

marcotroster
Автор

Thank you Arjan for all your videos, they have helped me becoming a better programmer! What is the rationale for an empty return vs no return at all?

virolana
Автор

Why not using the cmd module in the standard library ?

PascalLemaître
Автор

I am still waiting for a series about making a game! :)

grzegorzryznar
Автор

Great video!
Regarding the algorithmic function duplications... If you want to share code between the different commands - create a execute_algorithm_command function, that gets the algorithms dictionary, number of arguments, and the docs and then just partial apply the hash, encode and decode commands.
Alternatively you can do the same thing with a AlgorithmsExecutor class. This is also relevant for the api for the algorithms duplicate code.
One thing is that I don't like the printing mixed in with the application logic - what do you think about either making the data required to decide what to print returned from an inner layer function, or inject a presenter class and pass it events?

talwald
Автор

Could I ask what pattern or approach is using in this project? How could I define the structure before starting this kind of project?

Scorpisces
Автор

Disabling the squiggly lines in your code can be beneficial for visual clarity when creating Youtube videos, as it can be quite bothersome to have them scattered all over.!!!

samarbid
Автор

i don't like that you define COMMANDS as a constant, but then use add_command to modify it 🤔. very strange. Also parse_command_string doesn't look like it'll work well when a user tries to encode a string of two words for example. probably you missed it out cuz u didn't want to bother your code reviewers to review your code review 😂. overall, still useful, good luck w/ further vids!

andrewmenshicov
welcome to shbcf.ru