- 1 225
- 319 675
Jakubication
United States
Приєднався 31 бер 2016
Jakubication teaches you how to code, absent any pompousness and you'll only hear programmer-speak once a concept has been properly introduced. As a computer science graduate myself, I know what it feels like being on the wrong side of both of those, and I feel your pain. At the moment, I'm doing Python/Java/JavaScript content, but have plans for this channel to be a comprehensive guide for all the popular languages over time. I post every day but Sunday, so expect new long form videos six times a week!
JavaScript forEach vs Map
This video teaches about the array forEach vs map methods in JavaScript. The array forEach method performs a function on each element in an array. Critically, it cannot modify an exisiting array. The array map method on the other hand, performs a function on each element in an array, but can modify elements in the existing array.
Sections
0:00 - Array forEach
0:41 - Array Map
1:18 - Outro
#javascript #codingtutorial #learntocode
Sections
0:00 - Array forEach
0:41 - Array Map
1:18 - Outro
#javascript #codingtutorial #learntocode
Переглядів: 5
Відео
JavaScript Slice vs Splice
Переглядів 112 години тому
This video teaches about the array slice vs splice methods in JavaScript. The array slice method returns a shallow copy of a portion of an array from a starting to ending index. The array splice method changes the contents of an array by removing or replacing existing elements and/or adding new elements. Sections 0:00 - Array Slice 1:42 - Array Splice 2:31 - Outro #javascript #codingtutorial #l...
Python upper vs capitalize
Переглядів 39 годин тому
This video teaches about the upper vs capitalize string methods in Python. upper uppercases all of the characters in a string that can be uppercased. capitalizes, on the other hand only the first letter in a string with a group of words. #python #codingtutorial #learntocode
Python split vs splitlines
Переглядів 6112 годин тому
This video teaches about the split and splitlines string methods in Python. split splits a string into a list, and splitlines splits a string into a list of lines. This video delves deeper into how the methods work practically. #python #codingtutorial #learntocode
Python rsplit vs split
Переглядів 3114 годин тому
This video teaches about the rsplit vs split string methods in Python. rsplit splits a string into a list starting from the right, and split splits a string into a list starting from the left. This video delves deeper into how the methods work practically. #python #codingtutorial #learntocode
Python rfind vs find
Переглядів 516 годин тому
This video teaches about the find vs rfind string methods in Python. find returns the index the substring you are looking for starts at. rfind works similarly to find, although it starts searching from the end of the string, instead of the start of the string. #python #codingtutorial #learntocode
Python partition vs split
Переглядів 9919 годин тому
This video teaches about the partition vs split string methods in Python. partition partitions a string into a certain three element tuple, and split splits a string into a list. This video delves deeper into how the methods work practically. #python #codingtutorial #learntocode
SyntaxError: parameter without a default follows parameter with a default
Переглядів 421 день тому
SyntaxError: parameter without a default follows parameter with a default
SyntaxError: Missing parentheses in call to 'print'
Переглядів 821 день тому
SyntaxError: Missing parentheses in call to 'print'
How to Install Python 3.13.1 on Windows 10/11
Переглядів 36328 днів тому
How to Install Python 3.13.1 on Windows 10/11
error: continue statement not within loop
Переглядів 928 днів тому
error: continue statement not within loop
error: break statement not within loop or switch
Переглядів 2428 днів тому
error: break statement not within loop or switch
SyntaxError: Illegal break statement | JavaScript Errors
Переглядів 528 днів тому
SyntaxError: Illegal break statement | JavaScript Errors
SyntaxError: Illegal continue statement: no surrounding iteration statement | JavaScript Errors
Переглядів 628 днів тому
SyntaxError: Illegal continue statement: no surrounding iteration statement | JavaScript Errors
Example #3: it is not True that split of string with bunch of spaces gives 'h' and 'i' for each doubled space an empty string will be generated.
I ran the following code in Python and it generated just the list: ["h","i"]. print("h i".split()). So it looks like on this matter that you are mistaken.
@@jakubication yes, you're right when f-on split() has no arguments, but when separator argument is specified empty strings are generated (which is not intuitive at all). print("h i".split(" ")) generates ["h", "", "i"]
thank you
You're welcome
No .ToSting method...must be a crappy language.
Lol, you're not wrong
Because a small d double is not an object and only objects can have methods.
@@sevret313 all types, including concrete types, are derived from an Object.
@@erosnemesis No, primitive types in Java are not derived from Object.
@@sevret313 true but you could always use Double or Integer instead
Thanks
You're welcome 👍
Heres an idea for your next upload: How to increment an integer by 1? int x = 1; x++;
You joke, but this video is a part of a larger strategy to make sure my shorts are evergreen. No matter how simple the concept is, people in a regular consistent pattern search "how to convert double to float in Java'', on UA-cam. As people are searching that topic, my video comes up and I get consistent views
@jakubication maybe people would search how to increment an integer by 1, You should make a short about it too
now u got a long d... nice I would love to have double d s tho so idk if I would cast that
You do not need the explicit cast.
I just ran the code again, and it looks like you DO need the explicit cast. Omitting the explicit cast gives the possible lossy... error when you go to compile/run the code
@jakubication Thanks for the feedback. A search on Google tells me implicit cast in Java are only allowed if there is no information loss.
can you show us how to add 2 and 2?
That one's easy, 4. /s
@3:33 probably want to do rank and suit for the __str__ method. I was expecting you to go back and show the print card test you had done earlier, showing the __str__ method doing its job. Other suggestions: - if I'm extracting a single card from the deck, I'd call that "draw" - "deal" suggests to me an entire process of a hand to each player, so maybe deal would take in a hand_size and player_count, and deal out a list of cards for each player. - if we're extracting cards from the deck (with deal or draw or some other method), there probably ought to be a way to insert cards back into the deck when you're done with the hand. In some games, it's fine to "burn" the entire deck and start with a new deck, shuffled randomly, but I wouldn't presume this. - similarly, I'd leave the decision to shuffle the deck to the user of the class - when I buy a pristine deck of cards, it comes in a sorted order, and I think this is fine for our Deck class. If the user wants it shuffled, that's easy.
Yeah, you're right on that first part. That was simply a mistake I didn't catch in editing the video. As for you other suggestions, I would tend to agree. I'm pretty sure in making this video I had the implicit assumption that I could extend this code/video later for Blackjack. And that's how I made most of my design decisions. So: 1) Shuffling would be important within the deck class because unshuffled decks in blackjack would make an easy system to game, 2) There wouldn't be any concept of putting cards back in the deck, 3) Dealing would work fine because you would deal for the player and the dealer/house. Of course the calc_value logic would have to modified and the __str__ method would have to be fixed, but the rest would be easy to use in a game of blackjack.
The __init__() is the initializer, not a constructor. I wonder if this actually works. The calc_value() method should have been defined as a static method, otherwise the "rank" will be self, actually. Also I would still use letters for the suits, and use the __str__() method to do pretty print. The "ranks" and "suits" would also be class variables in my book.
I never actually knew that first part about constructor vs initializer. Thanks for the knowledge. I'm not certain on this, but I think because I called calc_value as a class method (using the name of the class, Card), that is why everything works as intended. Reasonable people can disagree on what to use/do for the suits. Finally, no disrespect, I see no world where ranks and suits would make sense as class variables. If you're having to "initialize" each card with __init__, shouldn't eàch card have instance variables? Or are you saying at the deck level it should have 52 class variables that each have a rank and suit? Ultimately I made the decisions I made in this video because I want to appeal to a beginner level audience. If I use time in the video to pontificate on constructor vs initializer, or introducing a new (to the viewer) kind of method like a static method, then I feel strongly like I'm disrespecting the viewer's intelligence and time. The aim of the video is just create a deck of cards in Python, so I try my best to avoid getting into the weeds.
@@jakubication You know it is an initializer, because it has "self" as parameter. So "self" should already been created, we are just giving values here. "that is why everything works as intended" I have tried, indeed it does work. But I would have added @staticmethod on top of the calc function and use "self" instead of Card. Because if you create an instance of the Card, - e.g. c = Card() - then calling c.calc_value() would throw an error. "I see no world where ranks and suits would make sense as class variables." I wrote "suits" not suits, because I meant the array you use to generate the deck and not a specific suit value. They could be class variables, so they can be queried from outside of the class as Deck.suits. Also "ranks" could be a dictionary, so that you can add a value to each, no need for a method to do that
straight forward and w, thanks
I am not a Python developer, but I think you could also use the ranks array index + 1 to get the rank value...
That may very well work, but I was always taught to make sure my code was easy to read/made sense/was intuitive. Just because the array indicies of the rank's happen to correlate to the value of the card, doesn't mean I should use that. But I do understand what you're saying, thanks for the suggestion.
That works for several of the cards in this case, but 10, J, Q all have value 10 and K has value 0 for the expected use case here, so you still need to special case those. For me, I'd probably put the rank to value computation in game logic, outside of the deck logic, which would make the deck and card classes reusable for many different games.
What IDE theme you are using?
Brogrammer, in Sublime
@@jakubication Thanks
Great example for practicing oop in python, thank you ❤
You're welcome! Glad you liked it 👍
In line 6 , why do you create another Card class within the Card constructor method , does that not create an infinite loop ? Also I feel to import a method to shuffle a list is cheating ? It could be better if you wrote your own function to shuffle it , maybe split the deck into n decks then merge them in alternating order m amount of times to mimic the riffle shuffle , it does not matter as long as your shuffle function is your own! Just giving the thumbs up for taking the time and courage to create it !
For you first point, I believe you're talking about the line, self.value = Card.calc_value(self.rank). That wouldn't create an infinite loop. It's written that way because, calc_value is a class method (belongs to the card class, not a particular card instance) so I couldn't call self.calc_value, so the only other option is to call Card.calc_value. And as for the shuffling method, I was always taught in college CS classes 3 main things, don't implement your own code to handle money (floating point imprecision), don't write your own cryptography code (someone smarter than you will surely crack it almost instantly), and don't write your own code to generate random values. (I don't remember the why for this one but presumably the answer is if this were apart of a serious gambling game at a casino, and you're randomness functionality was easily understood, then it's basically an easy money glitch). So that's my reason for that. Basically, if it's not the main part of the project I'm working on (the deck of cards and the cards themselves surely are the more important part then the cards being shuffled), then if someone has already written code for me to easily do a thing, then why reinvent the wheel. Hopefully that explains it. Thank you for the kind words at the end of your comment as well
> to import a method to shuffle a list is cheating ? random.shuffle() exists for exactly this reason. If you want to flex and write your own, you certainly can, and if it's fun, or if you're asked to for a programming interview, then sure. But for most use cases, the standard implementation is as good and better than one's own implementation. The OP gives 3 examples of when to not write your own implementation, but if the standard implementation works, then don't repeat the effort.
interesting
gracias, chaval
👍
Nice sir thanks
You're welcome 👍
They're not really comparable. IFs are for taking action given the logical result of a condition evaluation. TRY/EXCEPT are for responding to code that could fail, such as trying to open a file, and giving the program a chance to recover from the failure, not crash, present an error and potentially try an alternative command
I understand what you're saying and agree. My purpose in making the video wasn't necessarily that the two are comparable, just fulfillment of keyword research. Apparently people consistently search "Python if vs try", so I made this where I explain if, then try in a concise manner.
lol
wau... I loved
sudo rm -rf /
Good video btw
Thanks 👍 I always appreciate a kind viewer
I don’t know python but from a quick internet search where all the responses say that pass does nothing. It is my opinion that pass is a vital part of the python language due to the absence of begin/end blocks.
Yeah, you have to fudge the full reality a bit in a UA-cam short. pass definitely works as a placeholder that you can come back around later and fill in. But, strictly speaking, it doesn't evaluate to a value, and it doesn't change any state. Ultimately I would say it's up to the individual and how they would define "doing nothing" in code.
Yesh but what does this have to do with snakes?
Um, assuming this isn't sarcasm, Python is the name of the programming language from which I'm teaching the concepts in the video. It has nothing to do with snakes.
@jakubication program like choir programs? And language like you can speak it to other people? This is blowing my mind rn
Program like a set of instructions to make a computer do something. Language like a certain well-defined type of instructions to make a computer do something. Here's the first paragraph from the Wikipedia article for further reading: "A programming language is a system of notation for writing computer programs.[1] Programming languages are described in terms of their syntax (form) and semantics (meaning), usually defined by a formal language. Languages usually provide features such as a type system, variables, and mechanisms for error handling. An implementation of a programming language is required in order to execute programs, namely an interpreter or a compiler. An interpreter directly executes the source code, while a compiler produces an executable program."
@@jakubication oh like Minecraft
i love how to the point this was
Glad you liked it 👍
Can I get a byte of that :)
Lol 😂
What the mental gymnastics
That's JavaScript for ya
Underrated video
How
Although they look identical, because the two objects don't occupy the same memory address, JavaScript says they do not equal each other.
*break* can also occur inside switch statements legally. All else in the video is correct, though.
Very interesting short to get out of nowhere
24
Correct 👍
thx
Or Arrays.stream(arr).collect(Collectors.toList())
That works. Ultimately it's a balancing act between readability and conciseness
No, atleast this is not the best idea. This is an implicit cast. The same effect as d = (double)i (this is a c-style) cast. There's static_cast<T>, C-style casts, type punning using reinterpret_cast<T>, bit_cast, or using a memcpy call. const_cast<T> is almost always UB and should never be used. C style casts can have the same effect as a static cast combined with a const_cast. For C++ you'll want to use d = static_cast<double>(i); .
Thanks for the pointer 👍
How do you do it in Java?
Very similar to this, but you cast the double to an int on the same line you assign it to an int. I can't link to videos in comments because this is a short, but if you search "How To Convert Double Int In Java Jakubication", I have a video on this that will show you the code for how to do it. Cheers!
@@jakubication Found the video! It was very helpful! Thank you very much for your hard work :D
This was great content, keep it up👍
.. Cant you cast the integer?
Also that
Yes, but that wouldn't fit on the screen when trying to record the short. In real life code, though, it's just a matter of whether or not you prefer explicit (doing the cast) being better than implicit (what this code does).
right to the point, thanks
You're welcome
Thanks for this im glad the algorithm put this on my screen today as im learning python and Linux im subscribing to as many tutorials as i can My pc im building ready to start learning is nearly ready i cant wait
lol
no idea why this made me actually laugh out loud but it did
I always appreciate a viewer
@@jakubication please make more like this. want to write a function in c++? just write a function. this rules.
No. You should use std::static_cast<> and make it explicit. We write code for other programmers to understand.
Genuinely didn't even know std::static_cast<> was a thing. Thanks for the pointer 👍
thanks
You're welcome
In simple terms elif = else if
Correct 👍
thank u
You're welcome!
Sick, I don't know how this ended up on my feed, but seeing as Im learning java its nice to know
If you didn't already know, Java and JavaScript are very different languages. But, the concept of NaN (not a number) not being equal to anything applies across Java, JavaScript, and most other (if not all) languages
break is used to exit loops return is used to exit functions exit() is used to terminate the program But cool video man ;) keep it up
Thanks for the kind words. Yeah, I pinned a comment that pointed out my mistake
doesn’t exit actually terminate a program?and return is used to exit functions?
You're right, I got that wrong in the video