Oneliners are really something between an art form and a mental exercise. They might look cool, but they are quite difficult to write and even more difficult to read.
Good code must be simple and easy to comprehend for the casual human reader, so it should be structured, formatted and commented as good as possible. The reader is not supposed to spend hours to untangle unnecessarily compressed mumbo jumbo.
A lot of one-liners I see are not one-liners, they are just spaceless and escapeless codes lol
true one-liners are indeed cool looking and impressive, but they do not increase nor decrease performance, space, or time in any way.
The compiler ignores escapes and most spaces anyway, so one liners are treated about the same way formatted code is treated.
I agree with Javier Felipe Toribio, one-liners should be treated as a fun challenge, not a standard.
If your code is unreadable, poorly commented/documented it will be dismissed and criticized in the corporate world.
I agree with 「ＨＡＰＰＹ ＴＯ ＨＥＬＰ」 Some "wanna be" oneliners , aren't oneliners. IMHO a good oneliner is made of lambdas, recursive calls, pure mathematical functions and streams concatenating its inputs and outputs with stateless variables in a functional programming way
There are one-liners and then there are one-liners. Some of them are easy to read and indeed a bit more performant like for example a list comprehension (with not much more than a single ternary expression). This also applies when there is a built-in function. Both times the interpreter does access the underlying C-code more directly. In such cases you definitely should use one-liners.
Other one-liners are just for peeps who want to brag about them to newbies. Those very often use combinations of built-in functions which do the trick but can be even less performant than a longer code that is better fitted to the problem at hand.
Cbr✔[ Inactive ] I didn't say that the use of lambdas is mandatory in a oneliner. I said it's an option in a good one. I.e: Including user input. Like this : https://code.sololearn.com/cr32NWw9WY86/?ref=app
In addition to comprehensions and lambdas, f-strings are also a really handy tool for oneliners😁
Though I think they loosely qualify as OneLiners. This is one of my first, not quite the longest anymore
Javier Felipe Toribio i'm pretty good at oneliner and what do you mean by "a good oneliner is made of lambdas.."
Lambdas are user-defined function xd, you don't always need them , for example
Javier Felipe Toribio Cbr✔[ Inactive ] That is actually a very good example of the second kind of one-liner I mentioned... Hard to read and (much) less performant than a better fitting longer solution.
(I can still see the appeal of trying to write such a monster.)
Depends on situations
If you are in a competition of competitive coding , prefer one line codes as it takes less time is typing and are much more efficient
if you are making a project then go for formatted code as it increases readability of code and also helps you to identify bugs in your code easily
The thing with one-liners is, that it usually adds unnecessary complexity. For example the fibonacci code of Cbr✔[ Inactive ] could be solved in way less characters than her attempt. Thanks for proving 😉