r/learnprogramming • u/Temporary-Warthog250 • Apr 05 '22
Name one programming/comp sci concept you never understood and if you understand it, try to explain it to them
Name a programming concept such as virtual functions, pointers, certain algorithms, etc that you always had a hard time understanding and why.
Someone else who reads yours and does understand it, try to explain it to them to help them learn
1.6k
Upvotes
142
u/plastikmissile Apr 05 '22
Overloading functions
Say we have two functions. One adds only two numbers, while the other one adds three. Sure you can name them
AddTwo(x,y)andAddThree(x,y,z), but they do the same thing with slightly different arguments. So we it's better to just name themAdd(x,y)andAdd(x,y,z). Not only we do we avoid the confusion inherent in having two (or more) names for the same functionality, IDEs can pick those different signatures up so that when you type inAddit gives you the option to pick between the two versions for auto completion.Static functions
Let's go with that
Addfunction we talked about. Let's say it's in classMath. Being a function that adds the numbers in the arguments, it doesn't really care about the state of the class it's in, since it uses nothing from there. So you should be able to callAddwithout going through the trouble of instantiating the class. Instead of doing:You can just declare
Addstatic and go:Much neater, no?