+ 24
One liner code is better or format code
One liner code is better or format code coz it's fight between speed and understandable
45 Respostas
+ 46
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.
+ 10
I prefer readability. Although oneline codes bring more of a challenge and mental satisfaction, Python's beauty is in it's indentations ;)
+ 9
Clarity over cleverness.
+ 8
Oneliner is only for fun, as extra challenge. In real world jobs you must develope readable code in multiple lines with a lot of blank spaces
+ 7
I agree with 「HAPPY TO HELP」 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
+ 6
For a formal usage, I only write one-liners for functions when it is short and clear enough.
+ 6
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.
+ 5
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
+ 5
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
https://code.sololearn.com/chu0Xaheiq4W/?ref=app
+ 5
Above are some good one-liners, or at least not too bad, and let me show a very bad one.
https://code.sololearn.com/cZGiT4dCgn54
+ 3
Is good to one line a code but is better to use the normal format of writing codes
+ 3
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.)
+ 3
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
BUT
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
+ 3
I would prefer using neat code so that it's look nice and professional
+ 2
I try to understand one Cbr one line code and it is magic for me...
+ 2
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 😉
https://code.sololearn.com/cn5faURSpwLi/?ref=app
+ 2
Peter David Carter I know it's simple. I just appreciate the fact that they are *doing* stuff like that. Just the thought of keeping the community healthy😁
+ 2
Hi! I'm new to this community, but i was used to code in Atari BASIC as a teenager
Well, i used to one-line most of the times, and many of those programs were hard to read (even for me after a couple of months), then i got used to code more "formated" (Atari BASIC uses numbered lines) and comment main sections of the code, like define variables, read data, etc. so my programs became more readable
Anyway, now that i`m back in the coding world i`ll one-line every time i feel it does help to save memory, time and resources, as i did with most of my BASIC prograns
+ 2
Python does not use semicolons BUT needs FORMATTING .... HISS 😢
+ 2
No format = No python code (Python does not use semi-colons) 😂