Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 520 521 [522] 523 524 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 907938 times)

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #7815 on: September 14, 2015, 09:05:54 pm »

perl for president 2k16
I dunno, that sounds pretty much the same as Python in terms of dynamic-ness. Way more convenient though - especially with bless and but.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7816 on: September 14, 2015, 11:09:45 pm »

Dynamic typing is that thing where you can assign any type to any variable, right?

Why would you want that?
Logged

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #7817 on: September 14, 2015, 11:19:46 pm »

Convenience, mostly, though at the cost of occasionally sticking a string where you wanted a float.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7818 on: September 14, 2015, 11:28:26 pm »

Some days I just want to put an Integer, a string, a Banana, a nothing, and another array inside an array.
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7819 on: September 15, 2015, 12:22:55 am »

The reason I liked it in Python is that it wouldn't flip a shit when trying to concatenate strings with various other things. And when using a strong-typed language, "forgot the type declaration" is usually the first stupid mistake I make.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7820 on: September 15, 2015, 12:27:32 am »

Dynamic typing is that thing where you can assign any type to any variable, right?

Why would you want that?
Same reason you want modular functions that you don't need to know the inner workings of in order to use, just how to call them, what they expect as input, and all that other neat stuff abstraction brings.

Dynamic typing means that types aren't checked until runtime; I think it's a prerequisite for ducktyping, which means that types aren't strictly enforced but you'll get runtime errors when you try to call a method that isn't defined for a particular type. I'm not sure which one allows you to suddenly change a variable's type whenever by something like

Code: [Select]
a = 1
a = 'alpha'

But anyway, the reason you'd want it is so that you no longer have to worry about types. Instead, you trust that everybody who defined a type did their job properly, so that the methods you call are defined as you expect, and that everybody who uses your code does their job properly, so that they don't feed your code objects without the methods you need. Same way that when you write a function, you trust that the functions you use do what the documentation says, and you trust that users of yours will read your documentation, without anybody needing to dig into anybody else's source code. The idea is that you can say, "Okay, I'm not going to write a different function for adding integers than for floats, I'm just going to use exactly the same logic and assume that adding means basically the same thing for either one".

It adds convenience, and reduces the amount of stuff you need to understand in order to make your code function, provided nothing goes wrong. Of course, things always go wrong, and ducktyping can be an absolute nightmare to debug (for example, somebody unwittingly passes a string to your function, which cheerfully says, "Oh, you mean to concatenate these things!" and moves on until something three functions up breaks because how the fuck am I supposed to square root the string 'foobar').

If understanding your code is the hardest part of your job, ducktyping helps. If debugging is the hardest part of your job, it will quite possibly make things worse. At least, that's my understanding of the question.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7821 on: September 15, 2015, 12:28:07 am »

C# has static typing and doesn't have a problem with adding things to strings.

"One" + 1 = "One1"
Logged

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7822 on: September 15, 2015, 12:51:35 am »

Yeah, that's because they overloaded the operator. That's a hardcoded version of the same sort of thing - "+" figures out what it's supposed to be doing based on the types of the operands. Duck typing lets programmers do that sort of overload with their own code. Say you write a screen_update() function that takes as an argument an object obj, checks several bits of context like whether it's onscreen, behind some other bit of the GUI, etc., and then calls obj.draw(), passing it those bits of context to influence what it does on the screen.

With duck typing, you can write that function without knowing anything about those objects's types, because you don't actually care. You just need to be able to trust it has draw(), get_position(), get_size(), and so on, methods defined. You only need to write the function once, you don't need to mess around with any fancy argument declarations, and you don't even need to be able to anticipate every possible type that might get added when scope bloat inevitably occurs because an executive had a "great idea". Moreover, the user doesn't need to worry about any of that stuff either - they can just file the function away in headspace as "Thing what makes the pixels dance" and get on with whatever their job is.

Now, I don't know why it would be structured that way - maybe you're in charge of screen layout while the other stuff is being handled by an art asset team or something? It's a bit of a contrived example, like they almost always are. The point is, we've overloaded screen_update() to execute the same basic idea for any object type it makes sense to shove into the function, which makes it more convenient to use and simpler to grok.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7823 on: September 15, 2015, 03:13:41 am »

That's why you have generic functions, where you can say that "This input can be any type as long as it supports these functions"

So if you try to pass in a variable of a type that doesn't support draw(), get_position(), and get_size(), you'll get an error right there.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7824 on: September 15, 2015, 03:29:03 am »

ain't that

...

duck typing

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7825 on: September 15, 2015, 03:31:40 am »

It seems fairly similar...
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7826 on: September 15, 2015, 03:33:36 am »

Going by Bauglir's post, duck typing seems to not have any protections against passing in the wrong type.
Logged

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #7827 on: September 15, 2015, 03:34:55 am »

I think implicit type conversions got mixed in there somewhere. Python's both duck and dynamically typed, but "5" + 3 = TypeError, whereas some other languages will give you an 8 or a "53".
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7828 on: September 15, 2015, 03:40:02 am »

Yeah, that's the difference between strong and weak typing.
Logged
Taste my Paci-Fist

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7829 on: September 15, 2015, 04:21:31 am »

okay i was about to complain about strong typing being a really vague term with basically no meaning but then i did this in lua

Code: [Select]
("3"..5)*"2"
> 70

and i was like "yeah i guess that's what it means"

also, since we're talking about typing

Python 3.5's got type hints now
Pages: 1 ... 520 521 [522] 523 524 ... 796