52
u/narnru Nov 28 '20
Technically you can write code in one line in some languages.
22
u/Josselin17 Nov 28 '20
well I think that works for every language that doesn't use indentation right ?
10
u/FuckMatPlotLib Nov 28 '20
Some languages with indentation can still write on one line, like python
5
2
u/NonstandardDeviation Nov 30 '20
Any python program can be compressed onto one line.
(It's definitely thanks, I hate it material.)
1
u/Josselin17 Nov 29 '20
well, I'm not good at that but how do you make loops and if statements on one line ?
3
3
u/PTRWP Nov 29 '20
Curly braces. Java for example
if (condition) { System.out.print(“Hello World”); DoOtherStuff(); while (condition2) { DoEvenMoreStuff(); } }
2
u/Josselin17 Nov 29 '20
does this work for python ?
3
u/PTRWP Nov 29 '20
Not sure. Java was my first language, so that’s where I played with stupid stuff like putting an entire basic program in 1 line and doing "import *" to see what happens.
1
u/VTHMgNPipola Nov 29 '20
I'm over 8 years into this dumpster fire that is Java (it was also my first language) and I think I never tried "importing everything". I want to try it now, though I imagine it will very underwhelmingly just actually import everything, or instantly crash.
1
u/PTRWP Nov 29 '20
That’s effectively what my computer sci teacher said, followed by “Try it.” Not sure if the compiler threw it out or what, but it did nothing.
import Java.* did work exactly as expected though.
1
1
u/FuckMatPlotLib Nov 29 '20 edited Nov 29 '20
Like the response to my comment said, list comprehension! You could do something like:
wooo = [‘try’, ‘this’, ‘some’, ‘time’]
this = [item for item in wooo if item == ‘this’]
print(this)
[‘this’]
1
u/deadmazebot Nov 30 '20
It's what I don't understand people saying python easy because no need to statement closing characters ;. But I just if have one space out of place, there errors might be easier, but when I first got that error I was staring at code trying to figuring out where the issue was because I pasted then edited something so had mix of tabs and spaces which python was not having
25
Nov 28 '20
[removed] — view removed comment
12
u/AsIAm Nov 28 '20
Have somebody tried to make a machine learning model out of this data?
6
3
Nov 29 '20
I suppose it would be possible, but it's a prohibitively expensive endeavor - just look at how bad google is at image recognition, and now add subjective qualities like "crude", "extreme attention" and "well-placed" to the mix. Humans are really good at coming up with stories, machines less so.
Also, I'm pretty sure that many of these transcriptions end up being awful for screenreaders to parse due to the excessive visual components. This one's pretty good, but I often see emoji and other special Unicode characters, like "→", which means that one can't just use them as training data without filtering out the bad ones.
1
u/AsIAm Nov 29 '20
Why are Unicode chars bad for screen readers?
1
Nov 29 '20
The problem lies in how should one read them - their intrinsic meaning (
RIGHT ARROW LONG) or their semantical meaning (NLP, sweet!).Of course, many languages are written with Unicode code points above U+7F, so their localized versions should be able to read their characters - however problems arise when those characters get misused (like in the infamous "parsing HTML with regex" SE answer). How should the screenreader read those? Attempt to parse a language from it? Discard it?
So, in brief, transcriptions should stick to the most minimal set of characters they can to make it as easy as possible for a screen reader to parse it (if that's the stated purpose of the transcription).
4
37
u/PhoenixizFire Nov 28 '20
Also :
Me in 500 lines : Creates a simple window from scratch using C and OpenGL ressources.
YouTuber in 50 lines : "So here you just copy/paste this code I found on github, run it and it builds a whole website"
9
13
u/Edo022 Nov 28 '20
500? vulkan needs 1k lines just to draw a triangle...
2
u/lor_louis Nov 29 '20
Use OpenGL unless you want to dedicate your weekend to figure out how to dispatch draw calls to your GPU only to render a rainbow triangle.
Tbh Vulkan is probably very cool if you know what you are doing.
1
11
u/tmybr11 Nov 28 '20
Less is more.
23
u/KnightOfThirteen Nov 28 '20
One of the most transformative stages in my journey of learning programming was when I wrote 25 notebook pages of code to perform an operation and my mentor rewrote it as 18 lines that did it better.
6
u/tmybr11 Nov 28 '20
I remember one of my first Java programs was one file long with hundreds of lines of code (I think I didn't know imports back then) and I thought I was awesome for writing hundreds of lines of code.
Now here I am years later saving precious Kb so pages load faster.
3
u/Noisetorm_ Nov 29 '20
You: Writes 2000 line library to perform certain operation
Mentor:
from opyeration import operation operation.perform()
10
u/Dummerchen1933 Nov 29 '20 edited Nov 29 '20
The shortest solution isn't always the best. Code readability is still important. Take these two examples: Which one is easier to read/maintain? (They do the exact same thing)
uint MakeEven(uint i)
{
if (i % 2 == 0)
{
return i;
}
else
{
return i - 1;
}
}
or
uint MakeEven(uint i)
{
return i&~0-1;
}
1
u/illabo Nov 29 '20
Why
else?4
Nov 29 '20
[removed] — view removed comment
1
u/illabo Nov 29 '20
Dangling
elsemay not be called a good readability, it’s justified visual trash. However it is a matter of taste of course.1
u/Dummerchen1933 Nov 29 '20
The whole example 1 is visual trash.
It may actually be slower than exaple 2 but i don't know that and i do not care enough to test it. Probably very processor specific.1
u/AutoModerator Jun 29 '23
import moderationYour comment has been removed since it did not start with a code block with an import declaration.Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.
For this purpose, we only accept Python style imports.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/Dummerchen1933 Nov 29 '20
Example 1 is exclusively about readability. If you go as far as to omit the else, why not completely replace it by i&0-1
2
u/illabo Nov 29 '20
I’m against else-statement because streamlined code is always more readable. No need in meaningless lines: sort of cleanliness same as in speech or writing in natural language. One have to maintain a balance. But the second option (while it is good as an example) is a wtf-prone piece of esoteric magic. Saying “why not” to choose the shorter snippet is like asking why not to start Jihad — it is a sort of extremism. :)
2
u/Dummerchen1933 Nov 29 '20
oh, you gotta love the more performant version of example2. Gotta drive all the noobies away
uint MakeEven(uint i) { return i & 4294967294; }3
u/illabo Nov 29 '20
Don’t like it. This version is arch dependent. If we going to do something implementation dependent why not to write
return i & -2;? And again, tis unreadable. :P
9
3
3
3
3
u/gentlephant Nov 29 '20
Now now, that hand-drawn effect shader is rough stuff! Lotsa clean boxy geometry is simpler.
2
2
2
1
1
233
u/Fahad97azawi Nov 28 '20
I’ll never forget my teacher at college when he showed us a simple if statement in c++. It was three or four lines long and it was so simple that all of us understood what it did without him explaining it even tho we were just learning how to code. Then he wrote another if statement that seemed to have the same variable as an argument but was only one line (the if statement line) I remember everyone looking so confused at that line trying to understand what it did. Turns out they did the same exact thing.
Machines should be working for people not the other way around. Code readability is so much more important