Тёмный

What's Wrong With This Hello World? 

Dev Detour
Подписаться 23 тыс.
Просмотров 41 тыс.
50% 1

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.com/document/d/1Q...

Наука

Опубликовано:

 

22 дек 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 131   
@almightyhydra
@almightyhydra 5 месяцев назад
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.
@heckerhecker8246
@heckerhecker8246 5 месяцев назад
I already could guess html was doing something weird
@kreuner11
@kreuner11 5 месяцев назад
Nothing weird, such files are still allowed by spec
@heckerhecker8246
@heckerhecker8246 5 месяцев назад
@@kreuner11, html is just a weird "language"
@stacklysm
@stacklysm 5 месяцев назад
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 5 месяцев назад
unless it's CSS
@undefinedchannel9916
@undefinedchannel9916 5 месяцев назад
@@crossscar-devCSS ignore invalid lines
@stacklysm
@stacklysm 5 месяцев назад
@@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 4 месяца назад
@@stacklysmskill issue
@Kyoz
@Kyoz 5 месяцев назад
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.
@a.lollipop
@a.lollipop 5 месяцев назад
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 :)
@smergibblegibberish
@smergibblegibberish 5 месяцев назад
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 5 месяцев назад
I still use return 0 to this day, because IT'S THE LAW
@Mirage00000
@Mirage00000 5 месяцев назад
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 5 месяцев назад
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 5 месяцев назад
Only if you switch it to a void. if you do int main without a return, you’re absolutely disgusting.
@smergibblegibberish
@smergibblegibberish 5 месяцев назад
​@@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.
@Turalcar
@Turalcar 5 месяцев назад
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 4 месяца назад
Windows supports multi-arch binaries too
@rossjennings4755
@rossjennings4755 4 месяца назад
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.
@__christopher__
@__christopher__ 4 месяца назад
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; }.
@AByteofCode
@AByteofCode 5 месяцев назад
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 5 месяцев назад
Why not whitespace? More seriously, neat one. Most are more obviously hiding parts rather than sharing.
@AByteofCode
@AByteofCode 5 месяцев назад
​@@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 5 месяцев назад
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`
@trevorjamesconsideracion1982
@trevorjamesconsideracion1982 4 месяца назад
Wow really cool!!
@MonochromeWench
@MonochromeWench 5 месяцев назад
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
@U20E0
@U20E0 5 месяцев назад
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") }
@fadeoffical_
@fadeoffical_ 4 месяца назад
There is a bootable pdf document out there which can be booted up in a VM and also opened in a PDF reader
@georgecop9538
@georgecop9538 5 месяцев назад
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 /*)
@enderger5308
@enderger5308 4 месяца назад
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!
@sylv256
@sylv256 5 месяцев назад
i was not expecting to see 600 videos. this is criminally underrated and high quality content.
@k_otey
@k_otey 5 месяцев назад
he only has 8 videos
@__christopher__
@__christopher__ 4 месяца назад
@@k_otey So the expectations were met.
@qwoolrat
@qwoolrat 4 месяца назад
​@@k_otey well they didn't expect it anyways
@apricotapple4305
@apricotapple4305 4 месяца назад
​@@k_otey LMAO this made my day 😂
@FuneFox
@FuneFox 4 месяца назад
for my fellow brits, the "pound sign" is a hash. took me a little long to figure that out.
@RedStone576
@RedStone576 5 месяцев назад
ok now make a polyglot quine
@theuncalledfor
@theuncalledfor 4 месяца назад
Significant whitespace is a crime against humanity.
@MobCat_
@MobCat_ 5 месяцев назад
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.
@svgaming234
@svgaming234 5 месяцев назад
That is really impressive!
@justahumanwithamask4089
@justahumanwithamask4089 5 месяцев назад
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.
@daffa_fm4583
@daffa_fm4583 4 месяца назад
now i want to see someone code 2 different games in one file using 2 different programming languages
@spoobspoob2270
@spoobspoob2270 4 месяца назад
This is unbelievably cursed and I love ot
@Nickps
@Nickps 5 месяцев назад
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 5 месяцев назад
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 5 месяцев назад
@@devdetour Is there a reason (before introducing Brainfuck) that you would not put the stdio include in the first line?
@bene5431
@bene5431 4 месяца назад
​@@bryceiono
@RowanAckerman
@RowanAckerman 4 месяца назад
I think that one might be able to get it to work in MATLAB, FreeMat, and Octave with minimal difficulty..
@petemagnuson7357
@petemagnuson7357 4 месяца назад
It seems like rather than specifying "C or C++", you should average them out and just say C+
@robertyan5622
@robertyan5622 4 месяца назад
You say "in most sane languages" and one of the examples is Racket
@isodoubIet
@isodoubIet 4 месяца назад
I've used similar techniques to embed python scripts in C++ code. Quick and dirty but it works just fine.
@re.liable
@re.liable 5 месяцев назад
Ah I thought this was about Polyglot notebooks in VSCode. But still awesome regardless.
@m4rt_
@m4rt_ 5 месяцев назад
you could also do #include // document.documentElement.style.display="none"; #define print(str) int main(void) { printf(str " "); } // alert("Hello, World!"); print("Hello, World!")
@ShalevWen
@ShalevWen 4 месяца назад
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)
@Slackow
@Slackow 4 месяца назад
Couldn't you replace the #define foo bar with the include statement to simplify things?
@Name-uq3rr
@Name-uq3rr 5 месяцев назад
Next challenge: syntax highlighting
@mrblue61340
@mrblue61340 4 месяца назад
THIS IS ONE OF THE MOST COOL THINGS I HAVE EVER SEEN
@henryfleischer404
@henryfleischer404 5 месяцев назад
I did not know you could use Print to print in Ruby, I thought you had to use Puts.
@lazyalpaca7
@lazyalpaca7 5 месяцев назад
same here
@U20E0
@U20E0 5 месяцев назад
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_ 5 месяцев назад
and opposite is true for c@@U20E0
@hi12167pies
@hi12167pies 5 месяцев назад
this is really cool
@ElementEvilTeam
@ElementEvilTeam 12 дней назад
harro warudo
@qoombert
@qoombert 2 месяца назад
1st guess: it's a program that is designed to work in html, python and c.
@qoombert
@qoombert 2 месяца назад
i'm right
@TotalTimoTime
@TotalTimoTime 22 дня назад
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
@n_d_cisive
@n_d_cisive 5 месяцев назад
scrolled down only to see the criminally lacking number of comments. so here i am.
@moofymoo
@moofymoo 5 месяцев назад
Hello, World by Rick.
@ETHIOPIANCOFFEfan
@ETHIOPIANCOFFEfan 4 месяца назад
also make it work in assembly
@AnnasVirtual
@AnnasVirtual 5 месяцев назад
very cool
@NonTwinBrothers
@NonTwinBrothers 4 месяца назад
Decent
@Kat21
@Kat21 5 месяцев назад
nice
@markojojic6223
@markojojic6223 5 месяцев назад
Why not just use the load event?
@timnonik2736
@timnonik2736 4 месяца назад
Thanks, I was searching for this comment. Its something that can just be GPT'ed in a minute 🤷
@LodeStarYT
@LodeStarYT 5 месяцев назад
I was wondering if #define foo bar could be replaced with #include
@devdetour
@devdetour 5 месяцев назад
...yep that would totally work, not sure why I didn't think of it!
@Davo8899
@Davo8899 5 месяцев назад
thats not a pound sign, its a hash
@strangelf
@strangelf 5 месяцев назад
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 5 месяцев назад
@@strangelf the word "hashtag" came from the use of the HASH character to denote TAGS. It is a hash.
@jojojux
@jojojux 5 месяцев назад
As a german, I insist on calling it a rhombus.
@strangelf
@strangelf 5 месяцев назад
@@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
@digitalidoit
@digitalidoit 5 месяцев назад
@@strangelfWait, no. You both are wrong, it's a number sign!
@mrizkimaulidan
@mrizkimaulidan 5 месяцев назад
html changes a lot
@bforbiggy
@bforbiggy 5 месяцев назад
This is incredible, how does one's brain think of this
@jankiprasadsoni6793
@jankiprasadsoni6793 19 дней назад
Gaming
@brunocamposquenaoeoyoutuber
@brunocamposquenaoeoyoutuber 5 месяцев назад
Hi
@krispyking2450
@krispyking2450 5 месяцев назад
if there is a python 2 and 3 what about python 1
@devdetour
@devdetour 5 месяцев назад
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 5 месяцев назад
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 5 месяцев назад
ah ok thanks for clearing up the differences between them
@drooler420
@drooler420 5 месяцев назад
@@0LoneTechwait are u saying print doesnt work in py3? Because it definitely does
@0LoneTech
@0LoneTech 5 месяцев назад
@@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).
@its4theer
@its4theer 5 дней назад
i only know cpp 😬
@wattlefox
@wattlefox 4 месяца назад
add rust
@PMA_ReginaldBoscoG
@PMA_ReginaldBoscoG 5 месяцев назад
Would be good if you included java❤😊
@devdetour
@devdetour 5 месяцев назад
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 5 месяцев назад
@@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.👍
@orisphera
@orisphera 5 месяцев назад
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 5 месяцев назад
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.
@StopBuggingMeGoogleIHateYou
@StopBuggingMeGoogleIHateYou 5 месяцев назад
Zzzz
@apmcd47
@apmcd47 5 месяцев назад
Please stop calling # £
@aleksanderzdunek8647
@aleksanderzdunek8647 5 месяцев назад
Couldn't #include on line 1 replace the need to #define foo bar?
@yjlom
@yjlom 5 месяцев назад
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 5 месяцев назад
8:04 @JeffHykin noice found you :)
@callyral
@callyral 5 месяцев назад
why use define foo bar at the top instead of just including stdio.h there instead of below
@devdetour
@devdetour 5 месяцев назад
Yes, as another commenter mentioned I could have done it this way too - I just didn't think to!
@danielrhouck
@danielrhouck 4 месяца назад
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.
Далее
File Storage on YouTube | Project Showcase 1
4:21
Просмотров 753 тыс.
UZmir & Mira - Qani qani (Snippet)
00:26
Просмотров 526 тыс.
HELLUVA BOSS - THE FULL MOON  // S2: Episode 8
23:10
Why You Can't Visit 💀🎺.com
8:50
Просмотров 505 тыс.
a strange but powerful interview question
7:01
Просмотров 264 тыс.
Every Programming Language Ever Explained in 15 Minutes
15:29
The Bubble Sort Curve
19:18
Просмотров 393 тыс.
I Turned Bing Chat Into a Meal Delivery Service
8:46
What is polyglot programming and how do you apply it?
7:16
Stealing Storage from Discord
7:39
Просмотров 1,6 млн
But how hard IS Flow?
20:04
Просмотров 425 тыс.
Плохие и хорошие видеокарты
1:00
Bardak ile Projektör Nasıl Yapılır?
0:19
Просмотров 3,4 млн