Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 421 422 [423] 424 425 ... 796

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

hops

  • Bay Watcher
  • Secretary of Antifa
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6330 on: September 22, 2014, 04:39:24 am »

I'm asking if I can go "a = 1" and then later reassign it to "a = "Foo" " or not
Logged
she/her. (Pronouns vary over time.) The artist formerly known as Objective/Cinder.

One True Polycule with flame99 <3

Avatar by makowka

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6331 on: September 22, 2014, 04:43:53 am »

Code: [Select]
a=5

print(a)

a='five'

print(a)

just put this into repl.it

and since I'm not that kind of ass, the answer is yes

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6332 on: September 22, 2014, 06:24:58 am »

My mind cannot accept that.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6333 on: September 22, 2014, 07:02:37 am »

Do variables in Python have dynamic type?
The answer is, yes, they do. It's one of the strengths of Python! It also has ducktyping and strong typing. The former is probably beyond your current progress in Python right now, but the latter is easy to understand: you can't arbitrarily, say, add two differently typed variables together. 1 + "5" doesn't equal 6 nor 15, unlike Javascript.
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 #6334 on: September 22, 2014, 11:16:22 am »

C# will make that into "15",as a string,and won't let you assign strings to int variables
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6335 on: September 22, 2014, 12:19:12 pm »

I don't really like duck typing but that's probably since it'd seem like that would result in runtime errors when you change variables of something rather than compiletime errors.
It's probably a stupid reason though.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Squeegy

  • Bay Watcher
  • I don't really have any answers for you.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6336 on: September 22, 2014, 05:12:36 pm »

Dynamic types have their strengths and weaknesses. I actually like Java's non-dynamic variable typing, as I mentioned earlier in the thread, for some instances. Frankly, putting multiple types in a variable is bad practice anyway, because you might put it through functions that do need a specific type, which would crash the program if you weren't extremely careful. Those kinds of bugs can be very hard to root out in a large codebase.
Logged
I think I'm an alright guy. I just wanna live until I gotta die. I know I'm not perfect, but God knows I try.
Kobold Name Generator
⚔Dueling Blades⚔
Fertile Lands
The Emerald Isles

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #6337 on: September 22, 2014, 06:11:07 pm »

I've never actually used the dynamic type feature of Python. It does seem kind of strange, but I suppose it has its place.

I do like duck typing, however. Mostly because it saves having to type int (13) instead of just 13.
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.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6338 on: September 22, 2014, 06:27:44 pm »

I've never actually used the dynamic type feature of Python. It does seem kind of strange, but I suppose it has its place.

Code: [Select]
foo = load_string_from_external_source()
foo = int(foo) if foo.isdigit() else 0

It's a fairly common paradigm in the code I work on - we do lots of log parsing.
Logged

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #6339 on: September 22, 2014, 07:42:10 pm »

Well, there you go then.
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.

Squeegy

  • Bay Watcher
  • I don't really have any answers for you.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6340 on: September 22, 2014, 09:32:16 pm »

I've never actually used the dynamic type feature of Python. It does seem kind of strange, but I suppose it has its place.

Code: [Select]
foo = load_string_from_external_source()
foo = int(foo) if foo.isdigit() else 0

It's a fairly common paradigm in the code I work on - we do lots of log parsing.

See, basically what you're doing here is this:

Code: [Select]
int foo = int(load_string_from_external_source())

It can't be anything other than an integer, so what's the point of dynamic type? It just encourages sloppy coding.

If it's a duck, then say it's a duck. It's three to six letters out of your day.
« Last Edit: September 22, 2014, 09:49:30 pm by Squeegy »
Logged
I think I'm an alright guy. I just wanna live until I gotta die. I know I'm not perfect, but God knows I try.
Kobold Name Generator
⚔Dueling Blades⚔
Fertile Lands
The Emerald Isles

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #6341 on: September 22, 2014, 10:04:54 pm »

This
Code: [Select]
int foo
has no meaning in Python.
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.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6342 on: September 22, 2014, 10:07:27 pm »

See, basically what you're doing here is this:

It's a contrived example.

If there's one thing I've learned working in a mixed Python/.NET shop, it's that people have ideological beliefs about this that verge on religion. I'm not saying you are one of them, but it's futile for me to try to convince anyone.
« Last Edit: September 22, 2014, 10:09:37 pm by Mephisto »
Logged

Squeegy

  • Bay Watcher
  • I don't really have any answers for you.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6343 on: September 22, 2014, 10:09:56 pm »

This
Code: [Select]
int foo
has no meaning in Python.
ele
No shit, that's the point. Python has duck typing. Java doesn't. "int foo" means something in Java, and it's more precise and elegant.
Logged
I think I'm an alright guy. I just wanna live until I gotta die. I know I'm not perfect, but God knows I try.
Kobold Name Generator
⚔Dueling Blades⚔
Fertile Lands
The Emerald Isles

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #6344 on: September 22, 2014, 11:10:44 pm »

Code: [Select]
start

num firstOperand
num secondOperand
num myAnswer

input firstOperand
input secondOperand

call multiplyBot()
     myAnswer = firstOperand * secondOperand
     display myAnswer

end
Is this how modules work? It's just pseudo code, so I know there's no "right" way to do it, but is this logic functional? Does it make sense?

Task is to create a module that has two input parameters.
Logged
Pages: 1 ... 421 422 [423] 424 425 ... 796