What's Wrong With This Hello World?

  Рет қаралды 41,606

Dev Detour

Dev Detour

Күн бұрын

This hello world is weird. What's up with that? Well, it's not just 1 Hello World program...
I started a Discord server, come say hi, and drop your best polyglot hello worlds here! / discord
Resources doc (please let me know if I missed any!): docs.google.co...

Пікірлер: 131
@almightyhydra
@almightyhydra 8 ай бұрын
When I started my first job, IE6 was still a thing (ugh) and we used a polyglot hack to detect which browser the code was running on so we can do firefox or IE6-specific nonsense to fix the layout.
@Kyoz
@Kyoz 8 ай бұрын
reminds me of using encryption to create a single image that can transform into 20 other images depending on which decryption algorithm you use on it. something like: Take the target (the image or source code you want to hide) Decrypt the code using a specific key. (key can be whatever you want) This creates a jumbled nonsensical decrypted file of something that was never encrypted. comment out the decrypted mess and then copy and paste them to the bottom of the original image you want to encrypt. Then encrypt the original image. (the previously jumbled nonsense will unscramle and reveal the target image while the encryption simultaneously jumbles the source code or original image.) Basically a trojan horse.
@heckerhecker8246
@heckerhecker8246 9 ай бұрын
I already could guess html was doing something weird
@kreuner11
@kreuner11 9 ай бұрын
Nothing weird, such files are still allowed by spec
@heckerhecker8246
@heckerhecker8246 9 ай бұрын
@@kreuner11, html is just a weird "language"
@smergibblegibberish
@smergibblegibberish 9 ай бұрын
8:04 The parameter to print(x) is unused. Also, you don't need to write return 0 if you are using C99 or later. It isn't a problem, I just really want to mention it.
@totoshampoin
@totoshampoin 8 ай бұрын
I still use return 0 to this day, because IT'S THE LAW
@Mirage00000
@Mirage00000 8 ай бұрын
In C89 you could just create a function without a type and don't write return 0 too #include main() { printf("Hello World!"); }
@konstantinsotov6251
@konstantinsotov6251 8 ай бұрын
In gcc, you can do -Wno-implicit-int And use main without type with C99 or later And if you can omit return 0, it does not mean you should. Sometimes you want to return -1, or 127, or whatever, so it's better to be explicit and say "if the program reaches this point in code, it means that everything is fine"
@undefinedchannel9916
@undefinedchannel9916 8 ай бұрын
Only if you switch it to a void. if you do int main without a return, you’re absolutely disgusting.
@smergibblegibberish
@smergibblegibberish 8 ай бұрын
​@@undefinedchannel9916 No, C99 took void main out of the standard and added the ability to imply return 0 from int main. ------------------------ I'm not interested in arguing about wheather you should imply return 0. I just think it is interesting that you can.
@stacklysm
@stacklysm 9 ай бұрын
This looks like if Malbolge was human """readable"""". And HTML had to be the weirdest of the three, browsers are surprisingly lenient with invalid code
@crossscar-dev
@crossscar-dev 8 ай бұрын
unless it's CSS
@undefinedchannel9916
@undefinedchannel9916 8 ай бұрын
@@crossscar-devCSS ignore invalid lines
@stacklysm
@stacklysm 8 ай бұрын
@@undefinedchannel9916 It also ignores the developer, like, why can't my rulesets be applied the way I intended. Or I'm just lacking in the skill department
@snowwsquire
@snowwsquire 8 ай бұрын
@@stacklysmskill issue
@a.lollipop
@a.lollipop 8 ай бұрын
The file manager i use, ranger, uses this to have a bash script inside its binary file. If you run it with python, it will execute the python code normally, but when you exit the program you go back to whatever directory you were at when you opened it. If you instead source the binary with bash, it will run a script inside a multi-line string that will run the program and then change your working directory to whatever directory you were at when you closed it. Cool stuff :)
@Turalcar
@Turalcar 8 ай бұрын
One of the earliest IOCCC entries used polyglot machine code so the same binary could be run on PDP-11 and VAX. I think MacOS supported multi-arch binaries at some point but they just used different entry points for each one.
@bene5431
@bene5431 8 ай бұрын
Windows supports multi-arch binaries too
@__christopher__
@__christopher__ 8 ай бұрын
You can get rid of one duplication of the string "Hello world" by using the macro parameter in C. You still can add the " " in the macro by using the string concatenation feature in C, that is, "Hello world" " " is the same as "Hello world ". So you can write #define print(arg) int main() { printf(arg " "); return 0; }.
@rossjennings4755
@rossjennings4755 8 ай бұрын
I'm a bit surprised this works in Python 2, since print didn't become a function until Python 3, and at one point you had to include a line "from __future__ import print_function" in order to use it that way. I guess it's because, as long as you leave a space between the word "print" and the opening parenthesis, the parentheses are just treated as grouping the arguments of the print statement? Would have been interesting to mention that aspect.
@AByteofCode
@AByteofCode 8 ай бұрын
So far, my record is 5 (ruby, python, javascript, haskell & lua) but I like the #define idea so i'll try to improve on my polyglot For reference: a = 1; --a; 1 //2; console = type("console", (object, ), {"log": print})#/.to_s[7].to_i; puts "Hello World"; exit --a; print = console.log main = print("Hello World")
@0LoneTech
@0LoneTech 8 ай бұрын
Why not whitespace? More seriously, neat one. Most are more obviously hiding parts rather than sharing.
@AByteofCode
@AByteofCode 8 ай бұрын
​@@0LoneTech Using esolangs is a bit too easy, it felt like cheating so I imposed a "serious language only" challenge for my polyglotting
@joaohenrique03
@joaohenrique03 8 ай бұрын
nice but the Haskell version does have a different output, since print = putStrLn . show and show (for the STL objects) must output a valid Haskell expression as a string, adding quotes. you could fix it by changing your `print = console.log` stmt to `putStrLn = console.log`
@soIatido
@soIatido 8 ай бұрын
Wow really cool!!
@enderger5308
@enderger5308 8 ай бұрын
Ok, before watching this I read through it and can already see it’s devilishly clever. Using define with a multiline comment containing a Python multiline string and using HTML as a way to practically comment out the rest of the code for the JS solution is something I wouldn’t have thought of, nor would I have thought to define a 0 CLI output Python function to a macro defining the C main. This is brilliant!
@sylv512
@sylv512 9 ай бұрын
i was not expecting to see 600 videos. this is criminally underrated and high quality content.
@k_otey
@k_otey 8 ай бұрын
he only has 8 videos
@__christopher__
@__christopher__ 8 ай бұрын
@@k_otey So the expectations were met.
@qwoolrat
@qwoolrat 8 ай бұрын
​@@k_otey well they didn't expect it anyways
@apricotapple4305
@apricotapple4305 8 ай бұрын
​@@k_otey LMAO this made my day 😂
@MonochromeWench
@MonochromeWench 8 ай бұрын
Pure javascript instead of html would complicate things a bit as js is close syntax wise to C. I can't think of a way to do it but I'm sure it's possible. Just need a single C preprocessor statement that js ignores
@chri-k
@chri-k 8 ай бұрын
It's actually pretty easy if trigraphs are allowed: //??/ console.log("Hello from JS")/` #include //`/function main() { puts("Hello from C") } If they are not, and you use gcc, you can do this: [[eval("anything;process.exit()")]] main() { asm("anything") } If you are using ISO C instead, you can use C89 and do this: z = 0; console[0]; eval(z) { console[0] = 'i'; console[1] = 'n'; console[2] = 't'; console[3] = '='; console[4] = 'x'; console[5] = '='; console[6] = '>'; console[7] = 'x'; eval(console[0] + console[1] + console[2] + console[3] + console[4] + console[5] + console[6] + console[7]) eval((int)("anything;process.exit()")) }; main() { __asm__("anything") }
@petemagnuson7357
@petemagnuson7357 8 ай бұрын
It seems like rather than specifying "C or C++", you should average them out and just say C+
@fadeoffical_
@fadeoffical_ 7 ай бұрын
There is a bootable pdf document out there which can be booted up in a VM and also opened in a PDF reader
@FuneFox
@FuneFox 8 ай бұрын
for my fellow brits, the "pound sign" is a hash. took me a little long to figure that out.
@georgecop9538
@georgecop9538 8 ай бұрын
It depends what you use to exec it(if Python interp it will print 1 time because the rest is just comments, using html will alert hello world and ignore the rest and using GCC it would skip non C code because of /*)
@theuncalledfor
@theuncalledfor 8 ай бұрын
Significant whitespace is a crime against humanity.
@RedStone576
@RedStone576 8 ай бұрын
ok now make a polyglot quine
@robertyan5622
@robertyan5622 8 ай бұрын
You say "in most sane languages" and one of the examples is Racket
@Nickps
@Nickps 8 ай бұрын
I didn't get why we need the "#define foo bar" thing. In C/C++ empty preprocessor directives are allowed so just "# /*" should be fine, right?
@devdetour
@devdetour 8 ай бұрын
You’re right, looks like we could use a single “#” without the define foo bar. I didn’t know that was allowed in C/C++!
@bryceio
@bryceio 8 ай бұрын
@@devdetour Is there a reason (before introducing Brainfuck) that you would not put the stdio include in the first line?
@bene5431
@bene5431 8 ай бұрын
​@@bryceiono
@justahumanwithamask4089
@justahumanwithamask4089 9 ай бұрын
I thought he was going to display hello world in 3 languages as in something like English, Spanish and Mandarin depending on the language settings of the device.
@RowanAckerman
@RowanAckerman 8 ай бұрын
I think that one might be able to get it to work in MATLAB, FreeMat, and Octave with minimal difficulty..
@spoobspoob2270
@spoobspoob2270 8 ай бұрын
This is unbelievably cursed and I love ot
@isodoubIet
@isodoubIet 8 ай бұрын
I've used similar techniques to embed python scripts in C++ code. Quick and dirty but it works just fine.
@daffa_fm4583
@daffa_fm4583 8 ай бұрын
now i want to see someone code 2 different games in one file using 2 different programming languages
@ShalevWen
@ShalevWen 8 ай бұрын
Just saying, there are a lot of languages where empty file is valid syntax (pretty much every language that doesn't use a main function)
@qoombert
@qoombert 6 ай бұрын
1st guess: it's a program that is designed to work in html, python and c.
@qoombert
@qoombert 6 ай бұрын
i'm right
@re.liable
@re.liable 8 ай бұрын
Ah I thought this was about Polyglot notebooks in VSCode. But still awesome regardless.
@svgaming234
@svgaming234 9 ай бұрын
That is really impressive!
@ElementEvilTeam
@ElementEvilTeam 4 ай бұрын
harro warudo
@MobCat_
@MobCat_ 8 ай бұрын
php also uses echo and print for displaying text on a webpage. so you can do that and shove and exit; after it to stop it from running the rest of the code.
@mrblue61340
@mrblue61340 8 ай бұрын
THIS IS ONE OF THE MOST COOL THINGS I HAVE EVER SEEN
@henryfleischer404
@henryfleischer404 8 ай бұрын
I did not know you could use Print to print in Ruby, I thought you had to use Puts.
@lazyalpaca7
@lazyalpaca7 8 ай бұрын
same here
@chri-k
@chri-k 8 ай бұрын
the difference is that print does not print a newline, while puts does. There's also more printing functions: printf, p, and pp
@_kitaes_
@_kitaes_ 8 ай бұрын
and opposite is true for c@@chri-k
@m4rt_
@m4rt_ 9 ай бұрын
you could also do #include // document.documentElement.style.display="none"; #define print(str) int main(void) { printf(str " "); } // alert("Hello, World!"); print("Hello, World!")
@Slackow
@Slackow 8 ай бұрын
Couldn't you replace the #define foo bar with the include statement to simplify things?
@TotalTimoTime
@TotalTimoTime 4 ай бұрын
While I think the video is great, I would appreciate if you stopped flashbanging my eyes every time you switch to a screenshot. Some consistency in the brightness levels would be great
@ETHIOPIANCOFFEfan
@ETHIOPIANCOFFEfan 8 ай бұрын
also make it work in assembly
@NonTwinBrothers
@NonTwinBrothers 8 ай бұрын
Decent
@Name-uq3rr
@Name-uq3rr 8 ай бұрын
Next challenge: syntax highlighting
@bforbiggy
@bforbiggy 8 ай бұрын
This is incredible, how does one's brain think of this
@hi12167pies
@hi12167pies 9 ай бұрын
this is really cool
@LodeStarYT
@LodeStarYT 9 ай бұрын
I was wondering if #define foo bar could be replaced with #include
@devdetour
@devdetour 9 ай бұрын
...yep that would totally work, not sure why I didn't think of it!
@moofymoo
@moofymoo 8 ай бұрын
Hello, World by Rick.
@n_d_cisive
@n_d_cisive 9 ай бұрын
scrolled down only to see the criminally lacking number of comments. so here i am.
@Davo8899
@Davo8899 8 ай бұрын
thats not a pound sign, its a hash
@strangelf
@strangelf 8 ай бұрын
It is a pound sign; the word “hashtag” came from social media. The # sign was used well before social media, however, and is/was called the “Pound” sign.
@Davo8899
@Davo8899 8 ай бұрын
@@strangelf the word "hashtag" came from the use of the HASH character to denote TAGS. It is a hash.
@jojojux
@jojojux 8 ай бұрын
As a german, I insist on calling it a rhombus.
@strangelf
@strangelf 8 ай бұрын
@@Davo8899 we are both correct. Here is the Wikipedia article for this symbol, which states that “hash” and “pound” are both valid names. wikipedia /wiki/Number_sign
@the-digital-idiot
@the-digital-idiot 8 ай бұрын
@@strangelfWait, no. You both are wrong, it's a number sign!
@its4theer
@its4theer 3 ай бұрын
i only know cpp 😬
@jankiprasadsoni6793
@jankiprasadsoni6793 4 ай бұрын
Gaming
@krispyking2450
@krispyking2450 9 ай бұрын
if there is a python 2 and 3 what about python 1
@devdetour
@devdetour 9 ай бұрын
I didn't think to test with Python 1, but from a quick glance, it seems the syntax is quite close to Python 2 so perhaps this is also a valid Python 1 program!
@0LoneTech
@0LoneTech 8 ай бұрын
The reason people talk aso much of Python 2 and 3 is that Python 3 broke backward compatibility on a very common feature (the print statement was removed); having done one big break, they also pushed in some other cleanups (eg int vs long, bytes vs unicode, range vs xrange). Honestly the differences aren't that great, just not hiding behind formerly invalid syntax like C++ insists on.
@krispyking2450
@krispyking2450 8 ай бұрын
ah ok thanks for clearing up the differences between them
@drooler420
@drooler420 8 ай бұрын
@@0LoneTechwait are u saying print doesnt work in py3? Because it definitely does
@0LoneTech
@0LoneTech 8 ай бұрын
@@drooler420 Python 2 had a print statement. Python 3 has a print function. To learn of changes like these, have a look in "What’s New In Python 3.0" (there are detailed notes for each release back to 2.0).
@mrizkimaulidan
@mrizkimaulidan 8 ай бұрын
html changes a lot
@markojojic6223
@markojojic6223 8 ай бұрын
Why not just use the load event?
@timnonik2736
@timnonik2736 8 ай бұрын
Thanks, I was searching for this comment. Its something that can just be GPT'ed in a minute 🤷
@AnnasVirtual
@AnnasVirtual 8 ай бұрын
very cool
@wattlefox
@wattlefox 8 ай бұрын
add rust
@orisphera
@orisphera 9 ай бұрын
I think the following would be better: #define print(x) int main() { printf("%s ", x); } Or you can use #define float(x) int main() { float(1) #undef float(x) #define print(x) printf("%s ", x); print("Hello, World!") #define float(x) } float(1) #undef float(x) If we use C++ rather than C, we can replace with and `printf("%s", x)` with `std::cout
@devdetour
@devdetour 9 ай бұрын
Sure, this is definitely more concise, to optimize for least bytes this may be the way to go! If I remember right and if a quick search is to be trusted, std::cout is only valid C++ so we would lose C as a language.
@Kat21
@Kat21 9 ай бұрын
nice
@brunocamposquenaoeoyoutuber
@brunocamposquenaoeoyoutuber 9 ай бұрын
Hi
@PMA_ReginaldBoscoG
@PMA_ReginaldBoscoG 9 ай бұрын
Would be good if you included java❤😊
@devdetour
@devdetour 9 ай бұрын
I tried pretty hard to include Java too, but the problem I ran into is that Java's comment syntax is the same as C's, so it is hard to escape C code for Java and Java code for C. Some of the Code Golf solutions I looked at got around this by including some escape sequences, but even if I did this, I still think Java is completely incompatible with "#" characters, which I use heavily in this code. Now that I'm saying this though, I'm sure someone will prove me wrong :)
@PMA_ReginaldBoscoG
@PMA_ReginaldBoscoG 9 ай бұрын
@@devdetour Thank you so much. It's not easy to make code in multiple programming languages using a single file. But you did and you shared this knowledge to other people. Season's greetings man.👍
@StopBuggingMeGoogleIHateYou
@StopBuggingMeGoogleIHateYou 8 ай бұрын
Zzzz
@apmcd47
@apmcd47 8 ай бұрын
Please stop calling # £
@aleksanderzdunek8647
@aleksanderzdunek8647 8 ай бұрын
Couldn't #include on line 1 replace the need to #define foo bar?
@yjlom
@yjlom 9 ай бұрын
the best I could do, optimising for number of characters I also tried and failed to include common lisp and literate haskell, and this doesn't work with julia: #include//document.documentElement.style.display="none";alert("Hello, world!")\ "echo" "Hello, world!";"exit";"" #define print(x) int main(){puts(x);} print("hello, world!")
@RedCMD
@RedCMD 8 ай бұрын
8:04 @JeffHykin noice found you :)
@callyral
@callyral 8 ай бұрын
why use define foo bar at the top instead of just including stdio.h there instead of below
@devdetour
@devdetour 8 ай бұрын
Yes, as another commenter mentioned I could have done it this way too - I just didn't think to!
@danielrhouck
@danielrhouck 8 ай бұрын
I still donʼt understand why you need the `#define foo bar`. Couldnʼt you have started the C multiline comment on the `#include ` line? Thatʼd make the Brainfuck part harder or impossible but otherwise should work.
Nuxt and Stripe Tutorial #2 - Installation
3:40
Cody Bontecou
Рет қаралды 108
Caseoh Ps5 message compilation
14:55
Noah
Рет қаралды 963 М.
АЗАРТНИК 4 |СЕЗОН 2 Серия
31:45
Inter Production
Рет қаралды 1,1 МЛН
Touching Act of Kindness Brings Hope to the Homeless #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 19 МЛН
А ВЫ ЛЮБИТЕ ШКОЛУ?? #shorts
00:20
Паша Осадчий
Рет қаралды 8 МЛН
The CUTEST flower girl on YouTube (2019-2024)
00:10
Hungry FAM
Рет қаралды 53 МЛН
Stealing Storage from Telegram
11:11
Dev Detour
Рет қаралды 207 М.
I Turned Bing Chat Into a Meal Delivery Service
8:46
Dev Detour
Рет қаралды 14 М.
Dear Functional Bros
16:50
CodeAesthetic
Рет қаралды 506 М.
How Fast Can I Fill My Inbox?
13:30
Dev Detour
Рет қаралды 288 М.
When Your Game Is Bad But Your Optimisation Is Genius
8:52
Vercidium
Рет қаралды 1,5 МЛН
A problem so hard even Google relies on Random Chance
12:06
Breaking Taps
Рет қаралды 1,1 МЛН
I built my own 16-Bit CPU in Excel
15:45
Inkbox
Рет қаралды 1,4 МЛН
This Algorithm is 1,606,240% FASTER
13:31
ThePrimeagen
Рет қаралды 825 М.
This Site is Hilariously Unreadable - But it Wasn't Always
5:39
Dev Detour
Рет қаралды 197 М.
АЗАРТНИК 4 |СЕЗОН 2 Серия
31:45
Inter Production
Рет қаралды 1,1 МЛН