Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 76 77 [78] 79 80 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100519 times)

Killjoy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1155 on: August 18, 2013, 06:45:47 am »

What's the difference between Python 2.7 and 3.3?

Google it.

But in essence.

Optional Static Typing - Not used for anything at all in vanilla python.
Unicode Strings - Fuck string python 2.7 string formats....
New APIs - The networking modules are diferent as far as I know.
extended syntax for tuple unpacking - You can do something like this:
Code: [Select]
a, b*, c = range(1, 5) #a = 0, b = [1,2,3], c = 4

Oh yeah, and xrange has become deprecated.

It will take quite a while for python 3.x to be standard, problem is that the API is pretty unstable as of now. Major version immigration usually happens at major versions releases. Last one was 2.7 which is why it is being used right now by most people.
« Last Edit: August 18, 2013, 06:49:33 am by Killjoy »
Logged
Merchants Quest me programming a trading game with roguelike elements.

Kofthefens

  • Bay Watcher
  • Keep calm and OH GOD CAPYBARAS
    • View Profile
    • Marshland Games
Re: Programming Help Thread (For Dummies)
« Reply #1156 on: August 20, 2013, 08:47:11 pm »

My button in javascript does not work.

I have a chrome extensions that inserts a button into its window. The button appears correctly. If I say "clickElement(elementTitles[best])" in the javascript console, that works. However, when I click the button, nothing happens.

This is the relevant snippet of code. newDiv, elementTitles, etc are already defined, so that's not the issue.
Code: [Select]
  var btn = document.createElement("input");
  btn.type = "button";
  btn.value = "Buy best";
  btn.onclick = function(){clickElement(elementTitles[best])};
  newDiv.appendChild(btn);

I have used this as reference, as that seems to be the bit of code that isn't working.
Logged
I don't care about your indigestion-- How are you is a greeting, not a question.

The epic of Îton Sákrith
The Chronicles of HammerBlaze
My website - Free games

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!
Re: Programming Help Thread (For Dummies)
« Reply #1157 on: August 22, 2013, 10:46:29 am »

What's the difference between Python 2.7 and 3.3?

Google it.

-- SNIP --

Didn't know about static typing! Will need to look into it :D

The only difference I've personally experience when migrating from Python 2.7 to 3.3 was that I started using "print(x)" instead of "print x"... Unstable APIs and so forth are unlikely to affect anyone that's programming now, and seriously, it's better to start working with 3.3 right now than migrating a huge 2.7 project at a later date. At least that's my two cents!

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1158 on: August 22, 2013, 05:16:05 pm »

My button in javascript does not work.

I have a chrome extensions that inserts a button into its window. The button appears correctly. If I say "clickElement(elementTitles[best])" in the javascript console, that works. However, when I click the button, nothing happens.

This is the relevant snippet of code. newDiv, elementTitles, etc are already defined, so that's not the issue.
Code: [Select]
  var btn = document.createElement("input");
  btn.type = "button";
  btn.value = "Buy best";
  btn.onclick = function(){clickElement(elementTitles[best])};
  newDiv.appendChild(btn);

I have used this as reference, as that seems to be the bit of code that isn't working.

Are you sure all of them are set (including var best)? It works for me:  http://jsfiddle.net/tx2kz/
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Killjoy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1159 on: August 23, 2013, 06:20:16 am »

Didn't know about static typing! Will need to look into it :D
Okay it is not really static typing, it is optional type annotations.
It will never be used by vanilla python, but it is meant as a semantic feature available for other projects.

The only difference I've personally experience when migrating from Python 2.7 to 3.3 was that I started using "print(x)" instead of "print x"... Unstable APIs and so forth are unlikely to affect anyone that's programming now, and seriously, it's better to start working with 3.3 right now than migrating a huge 2.7 project at a later date. At least that's my two cents!
The reason people stick with 2.7 is because of the humongous community library available for python 2.7 not available in python 3.3. A lot of the community libraries are slowly moving towards 3.x, but they are still vary of API changes, dependencies and whatnot, so migration is very slow.

When we hit the last of the 3.x version numbers we will probably see 3.x gain much more support.
Logged
Merchants Quest me programming a trading game with roguelike elements.

olemars

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1160 on: August 23, 2013, 07:43:18 am »

Just in time for 4.x?

It's tremendously annoying to find one library that's gone over to 3.3 and one that requires 2.7, and you want both.
Logged

Killjoy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1161 on: August 23, 2013, 07:52:07 am »

Just in time for 4.x?

It's tremendously annoying to find one library that's gone over to 3.3 and one that requires 2.7, and you want both.

Actually current estimates suggest that the majority of the python community will have made the switch to 3.x just in time for version 7.x
Yes I am being sarcastic..
Logged
Merchants Quest me programming a trading game with roguelike elements.

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1162 on: September 01, 2013, 01:22:26 am »

C++ question.
Does dynamic casting take up a lot of time? As in, in comparison to adding/subtracting/making a variable on the free store/etc.

I have a dynamically-generated tree.
I have a Node_Base class, with the Node inheriting it, with a Seq_Node inheriting that. Node_Base has operations for making/changing/removing branches of the tree, the classes "above those" are used in other things. The problem is bad performance, and I'm suspecting the cause is the fact that I'm using dynamic_cast<Seq_Node>(some_pointer_to_node_base_or_node) everywhere.
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #1163 on: September 01, 2013, 01:24:28 am »

Did you try profiling it?
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

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1164 on: September 01, 2013, 01:53:35 am »

Dynamic casting is rather time consuming. Is there any particular reason you are casting a derived class to a base class?
Logged

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1165 on: September 01, 2013, 02:40:28 am »

Did you try profiling it?
No, at least not how I understand it. Please explain.

Dynamic casting is rather time consuming. Is there any particular reason you are casting a derived class to a base class?
Well, crap. I wanted to have a more "correct" model, with "one class doing one job", so that it would be "easier to debug". I guess I'll have to rewrite it all again... :P
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #1166 on: September 01, 2013, 04:02:24 am »

If you use a profiler, you can pinpoint where exactly it is slow, can't you?
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

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1167 on: September 01, 2013, 04:10:54 am »

Derpity derp derp.
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.

Killjoy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1168 on: September 01, 2013, 06:52:05 am »

Derpity derp derp.

Stop worrying about performance. Dynamic casts does have a performance hit, but it is negligible in the large context. Unless you have actually pinpointed it to be a bottleneck.

Besides, if you are just casting to base class, then don't use the dynamic cast, just cast it the C way.
Logged
Merchants Quest me programming a trading game with roguelike elements.

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1169 on: September 01, 2013, 07:59:29 am »

The problem is, I'm doing a bunch of calculations that involve getting children/parents in the tree and their properties. As in, every time I'm referencing a node (a lot of times), I need to dynamic_cast. And I am using pointers, is it possible to do that with (typeb)typea casting?
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.
Pages: 1 ... 76 77 [78] 79 80 ... 91