Got to respect C for replying "NO! Do it yourself!" when you ask it to do something simple
@mCoding3 жыл бұрын
It stays true to the principle of least surprise, which makes it a very stable and easy to learn language!
@vandelayindustries29713 жыл бұрын
@@mCoding Easy to learn, hard to master ;-)
@berylliosis52503 жыл бұрын
It stays true to the principle of least surprise... until you learn about Strict Aliasing/all the other wonderful sources of UB ;P I think (safe) Rust stays true to that though, as long as you don't write surprising deref impls
@Kitulous3 жыл бұрын
no, I don't respect a language that makes you WET. or thrice. or four times. or in almost every project.
@angel-ig3 жыл бұрын
I *_C_* you're a man of culture...
@MattGodbolt3 жыл бұрын
Ok ok hint taken :) I'll look at getting newer pythons in!
@MattGodbolt3 жыл бұрын
Alright, the site's updating with python 3.9.6 enabled; should be there in the next ten minutes or so :) Feel free to ping me directly next time (file an issue on our GH, or ping us on our discord (linked from the GH page)) :) Great stuff: enjoyed the video too!
@mCoding3 жыл бұрын
@@MattGodbolt You work fast! Thanks so much, I'll try to remember to ping you the day that 3.10 is released :)
@MattGodbolt3 жыл бұрын
@Fooobos Nom There's always so much to learn!
@parlor31153 жыл бұрын
"convert your x to a bool yourself" really sounds like something C would say
@dominat0r36003 жыл бұрын
"I saw the viewer count drop off last time I showed the docs, so we're not going to do that" I see, a man of culture
@yxlxfxf3 жыл бұрын
really enjoying c++ content on this channel, hope to see more in the future :)
@guilhermedantas50673 жыл бұрын
3:33 Actually, in this case the string "" IS pointing to a terminator character.
@mCoding3 жыл бұрын
You are technically correct, the best kind of correct.
@Yazan_Majdalawi2 жыл бұрын
@@mCoding I don't get it... is there a case where that wouldn't be true? What's the difference between what he said and what you said? And why is he "technically correct" and not "correct" Sorry I couldn't understand what happened here ^^
@0LoneTech Жыл бұрын
@@Yazan_Majdalawi The best kind of correct is a reference to Futurama, just as bestagons are a reference to CGP Grey. They did indeed say the same thing.
@abt86013 жыл бұрын
Well, in this respect Haskell is way simpler than Python, C++, and C, even though Haskell is considered a difficult language to learn. In an if-then-else expression, if the condition isn't an expression of type Bool, the compiler or the interpreter yells at you. No number types and container types are allowed. Also, Haskell doesn't do implicit conversions.
@berylliosis52503 жыл бұрын
Rust has the same deal, and I think C# does too. I don't mind having additional ways to get truthiness (C is okay), but bool-only is a MUCH better decision than the nightmares that are Python and C++
@xelaxander3 жыл бұрын
@@berylliosis5250 True, I use Python a lot and I always distrust that feature. Say I want an optional numeric argument x with branching in a function. I cannot simply use the truthyness of x to determine the branch since both 0 and None evaluate to False.
@johannestafelmaier616 Жыл бұрын
Boolean conversion is yet another feature that may have sounded nice as an idea but can cause so many problems. Intuitive is good. Boolean conversion is not intuitive. (see difference C++ and Python). Glad Haskell "agrees" :)
@rcatyvr3 жыл бұрын
Good description. I always used it that way, unknowingly, from bash and zsh scripts where if = if object exists/is true: anything that can resolve to a 0 or a non-zero, which is to say, a Boolean.
@kaosce3 жыл бұрын
As a C++ and Python lover, this episode is perfect and reminds me of Jason Turner's !
@mCoding3 жыл бұрын
I'm a big fan of Jason and his videos!
@photon61563 жыл бұрын
Before I pressed like button, it was 256 likes and 0 dislikes. I'm gonna hate myself for breaking this beauty for the rest of my life
@CodingDragon043 жыл бұрын
Just like jameson, the production quality of the videos is going up exponentially!
@hunterwilhelm3 жыл бұрын
Jameson! Dude singlehandedly increased total per month by more than 2 times. Literally 2^n and he said let's n++
@hunterwilhelm3 жыл бұрын
Give or take $1
@georgesanderson9183 жыл бұрын
Yes! A good way to check what's efficient is sometimes by disassembling your code, I use dis module built into the standard library! I think the word things like LOAD_CONST are called opcodes, that have an assigned integer, the cool and weird thing you can do with these opcodes and Python disassembler is actually change them while the code is running, so I think you can inject opcodes into your python operations, you'd need to implement a metaclass system and use the sys module to get the code frames, then dissassmble them with the dis module, and then just check for your target opcodes and switch them out, pretty useless comment and thing to do but, you know Great video though, I loved it, very informative!
@-reijne40203 жыл бұрын
Loving it man, good deep dive
@john.dough.3 жыл бұрын
Very interesting! Thanks for expanding the scope of your videos to more than just python!
@TheZethera3 жыл бұрын
Rust takes the most restrictive approach, having a dedicated Boolean type and only allowing it in if statements. Nothing else has a "truthyness".
@ammyvl13 жыл бұрын
Honestly I wish it were a bool trait
@TheZethera3 жыл бұрын
@@ammyvl1 if you want to be cheeky you could override the ! operator and use that to produce a Boolean value for your type.
@jetison3333 жыл бұрын
This kind of makes the most sense to me, I mean if you want a true or false value out of a different object surely you should just write whatever check you actually want to check and not leave it pretty ambiguous.
@berylliosis52503 жыл бұрын
"if let" sort of replaces any advanced truthiness detection like that. Most situations (I can think of) where an explicit function call is cumbersome can be rewritten with the construct.
@Aidiakapi3 жыл бұрын
@@ammyvl1 I disagree. Something like if collection.is_empty() { } or if integer != 0 { } is much more readable than if collection { } or if integer { }.
@stolenlaptop Жыл бұрын
Regarding c, stdbool.h, enums and "if( x )" works fine as an int as given the function driven nature of c, return 1 return 0 and return -1 are very common.
@LunaDragofelis3 жыл бұрын
I vastly prefer the Java way, where only booleans can be used as booleans. int num = 0; String text = "Luna Saphira Dragofelis"; if (text == null || text.isEmpty()) { System.out.println("text is empty or null"); // note that text.isEmpty() alone would throw a NullPointerException if text was null, since no methods can be called on null // alternatives: text.length() == 0 and text.equals("") // text == "" won't reliably work since that won't compare the value, but instead if it's the same string instance } else if (num == 0) { System.out.println("num is zero"); } else { System.out.println("num is nonzero and text is not empty"); }
@iltrovatoremanrico3 жыл бұрын
Great vid, very informative!
@robertbrummayer49083 жыл бұрын
Great video!
@yc6913 жыл бұрын
great video as usual :)
@mCoding3 жыл бұрын
Thank you! Cheers!
@jupyter5k6473 жыл бұрын
I knew this pretty well, but not in byte code depth 😂, just came to know about these concepts by doing a project. Really nice explaination btw :)
@mCoding3 жыл бұрын
I find it is always beneficial to dig into even the most basic foundations. Often there are things I've missed even after decades of programming! Thanks for your kind words, they don't go unnoticed!
@slycordinator3 жыл бұрын
Wrt the empty string being false, I don't like the common recommendation that you should do [if not var:] instead of [if var == "":]. Yes, the former is shorter and likely a bit faster, but the latter is easier to immediately see exactly what you're checking for. And it will only get triggered when the thing is actually the empty string like you wanted to check for.
@seb_iic51823 жыл бұрын
1:49 why does he say it only works up to Python 3.8 HINT HINT. Has something changed in version 3.9? Very interested what it is :)
@mCoding3 жыл бұрын
At the time of making this video, Compiler Explorer supported up to Python 3.8, whereas 3.9 was the most recent version. I knew that person in charge of Compiler Explorer watches my videos, so the hint hint was just for him. It was updated to include Python 3.9 very quickly :)
@lucaspacheco10813 жыл бұрын
This is really great
@Caarve3 жыл бұрын
Cool video
@unovillegas68683 жыл бұрын
2:18 oh god a goto in line 3650
@megaing13223 жыл бұрын
You don't want to see the rest of the function (e.g. the file. There is only one function in the file)
@Alche_mist3 жыл бұрын
That said, `goto error` in plain C is one of the valid ways of error handling and one of the least frowned-upon cases of goto ever.
@plato4ek2 жыл бұрын
0:40 Wait a minute! Non-empty list even filled with zeroes is a _truthy_ value! In Python. Checked in 3.8.
@plato4ek2 жыл бұрын
OK, looks like i misunderstood what you've said. You meant single values in that list.
@mCoding2 жыл бұрын
Yeah the truth value is determined by the length of the list
@photon61563 жыл бұрын
Why it says that this video includes payed promotions, is it because of patreon?
@mCoding3 жыл бұрын
I include affiliate links in the description, and according to yt terms such links are sponsored content, though many youtubers don't mark them as such.
@evilgordita3 жыл бұрын
Many of the KZbinrs I watch will declare the sponsors in the videos themselves and their respective descriptions but don't checkmark the flag for the video. I vaguely recall Mr. Tech Tips himself once saying he doesn't use the Sponsored Content flag because it appears to have side-effects of some sort that he finds undesirable and considers the way he points out his sponsors in his videos to be adequate in fulfilling the need to disclose them.
@ExCyberino3 жыл бұрын
waht you mean when you say CPython?
@mCoding3 жыл бұрын
Python is a language specification, but someone has to implement it and turn it into a program you can actually execute on a computer. The default reference implementation of Python is written in C and it's called CPython. There are other implementations, e.g. Jython, PyPy, and IronPython.
@ExCyberino3 жыл бұрын
@@mCoding Thank you alot, Also is there a way to write in C and convert into some library to be used as python. Let's say I have a function written in C that sums a list, and i want it to be used in Python as a function called mylib.sum(), Could i do that? if so, how?
@Alche_mist3 жыл бұрын
@@ExCyberino I don't know _how_ you do that, but it totally can be done. That's exactly what the powerful number-crunching libraries (like numpy, scipy or the machine learning ones) do. And for the specific cases of summing huge lists etc., an advisable approach would be not to reinvent the wheel and have a look into numpy, which is all about manipulation of large numerical arrays by calling C (or even Fortran) backend from Python.
@yonataneavri82983 жыл бұрын
hmm, pretty sure __nonzero__ also has something to do with this but i had a really hard time understanding it. if someone knows how it works please tell me.
@megaing13223 жыл бұрын
Old name for __bool__ in python2.7
@mCoding3 жыл бұрын
Indeed, Python 2 used __nonzero__ instead of __bool__, it was renamed for Python3. Since Python 2 is well past its end of life, I do not mention it in the video.
@Econcrafter3 жыл бұрын
I never get this problem. Just add an " == 0" or "== []" and there is no issue. Sure you can use the types builtin bool methods but by doing that, you create issues like these and it makes code less readable albeit only slightly. "while lst: lst.pop()" is more confusing than "while len(lst) != 0: lst.pop()". Read that out loud and it is immediately clear what it is doing as opposed to having to adjust it in your head.
@erwinmulder13383 жыл бұрын
I always found the 'if x' construction lazy and at worst ambiguous code. The only time I can see some validity is than you have lazy type evaluation (like in Python) and you don't actually know what type of data you're working with and don't care.
@alekseikolupaev99413 жыл бұрын
I wander how nobody pointed out that containers are not false if they are not empty, and two containers in your false_things function are not false actually
@alekseikolupaev99413 жыл бұрын
I understand what did you want to explain, but this code is confusing for me
@mCoding3 жыл бұрын
Indeed, the rule that I mention in the video is that empty containers are False, and that nonempty containers are True. This is in agreement with what you mentioned. >>> print(bool(False)) print(bool(None)) print(bool(0)) print(bool(0.0)) print(bool(0.0+0.0j)) print(bool(set())) print(bool({})) print(bool([])) print(bool("")) False False False False False False False False False I'm confident all of these objects are false and that the rule is that empty containers are false. See docs.python.org/3/library/stdtypes.html#truth-value-testing. Which two of these do you think are True?
@wilmhit3 жыл бұрын
chad C. Do it explicitly! ~ shouted some computer engineer in '60. People still haven't learned that over half a century later. BTW Odysee upload would be nice.
@stef90193 жыл бұрын
Discord gang.
@mCoding3 жыл бұрын
Let's get some new members!
@markcuello52 жыл бұрын
HELP
@yohannboniface37713 жыл бұрын
first :)
@mCoding3 жыл бұрын
Perks of Patron/Donor gang I guess.
@yohannboniface37713 жыл бұрын
@@duckasdfjfasd :P
@cmyk89643 жыл бұрын
Python: "" is False because it’s empty C++: "" is true because it doesn’t point to null C: What the hell are you two FUCKING TALKING ABOUT
@MithicSpirit3 жыл бұрын
Discord gang
@lunarmagpie43053 жыл бұрын
discord gang
@akj73 жыл бұрын
Why are you using Python logic in C and C++, i guess maybe so your viewers can understand. There are no such thing as a string in C++ or C. C doesn't have a string type neither does C++. In C++, there is std::string, whose implementation depends on compilers and SSO implementatioms. There is std::string_view in C++ too. Calling "" a string in C and C++ is already wrong (Yes, i know it is for the viewers.). Java makes a distinctions between primitive types and boxes, i.e. long and Long. This explains why people have issues learning C or C++. They try to learn C and C++ from a wrong point of view. The trick is going from the memory-like perspective. 2 is not a number (JavaScript, Python, ...), it is an int placed on the stack with a usual representation: 0x02, 0x00, 0x00, 0x00 (in C, C++, Rust, ...).