Lounge of Tomorrow

Lounge of Tomorrow (http://74.208.121.111/LoT/index.php)
-   Egg Head (http://74.208.121.111/LoT/forumdisplay.php?f=13)
-   -   A question for any code jockeys (http://74.208.121.111/LoT/showthread.php?t=10523)

Kevy Baby 05-14-2010 02:10 PM

Quote:

Originally Posted by scaeagles (Post 323258)
At 6'1, I am the 2nd shortest person in my 8 person development department. Shortest guy is 6'0. I would guess that means no.

Yeah, but your, well... you

Ghoulish Delight 05-27-2010 10:39 AM

Wow. In just 2 weeks I've learned (and retained) more about programming (well, Python) than the whole of the last 14 years combined. It's amazing how much easier it is to make sense of it all when I have a practical goal that I actually give a crap about rather than arbitrary exercises thought up by professors and text book writers. Concepts that I once only vaguely grasped in isolation but could never wrap my brain around how to use them in any sort of practical code are suddenly crystal clear.

Disneyphile 05-27-2010 10:44 AM

GD, for Action Script, I look for basic code online (most programmers share code), cut and paste it, then modify it to my needs.

Not sure if that can work in other languages, but it's a huge time saver in AS. I still have to know what the code is doing in order to modify it, but I've been able to accomplish some really awesome stuff in a short period of time with "starter code". :)

Ghoulish Delight 05-27-2010 10:49 AM

What I'm coding is pretty low-level and specific, there aren't many people who are trying to accomplish exactly what I am, so there's not much code that I can simply paste. Plus, as a general rule, I learn better by building up rather than untangling existing code. But as a source of examples of how individual calls and commands work, the internet is obviously invaluable.

Ghoulish Delight 05-27-2010 11:18 AM

Incidentally, I have a question for anyone familiar with Python.

Is there a way to tell the interpreter that certain commands MUST be executed in order?

e.g.

Quote:

class MyClass():
....def __init__(self, var1):
....self.var1=var1

....def Method1(self):
........subprocess.call("os call")
........return


def main():
....ClassList=[]

....for i in range(5):
........ ClassList.append(MyClass(i))

....for j in ClassList:
........j.Method1()
........subprocess.call("os call")
........ other work




main()
When I run this and it gets to that 2nd loop instead of executing as:
ClassList[0].Method1()
subprocess.call
other work
ClassList[1].Method1()
subprocess.call
other work
ClassList[2].Method1(0
....

I get:
ClassList[0].Method1()
ClassList[1].Method1()
ClassList[2].Method1()
ClassList[3].Method1()
ClassList[4].Method1()
subprocess.call
other work
subprocess.call
other work
subprocess.call
other work
subprocess.call
other work
subprocess.call
other work


Clearly what's happening is that the interpreter looks at Method1, decides that it's not doing anything that is internally dependent on order of execution, so it optimizes by lumping all 5 executions together. The problem is, the results of the subprocess call ARE dependent on order of execution.

I came up with a workaround. I threw a dummy variable assignment (garbage=self.var1) at the end of Method1. That's enough to convince the interpreter that work is being done and it should keep things in order. But that seems inelegant. Is there a better way to stop the interpreter from thinking it knows better than me?

Kevy Baby 05-27-2010 11:37 AM

I don't know why I keep clicking in this thread.

scaeagles 05-27-2010 11:49 AM

Don't know python, but pretty much every language I've ever worked with has to be tricked in certain circumstances. Code isn't always pretty....I just comment a lot in the code when I have to do the "inelegant".

Ghoulish Delight 05-27-2010 12:55 PM

I suppose that level of control is one of the many things one sacrifices for the convenience of not having to fuss around with malloc.

Capt Jack 05-27-2010 02:56 PM

are you sure python recognizes indexing as zero relative? Ive never used (or honestly ever heard of) Python, but I know some languages vary on that aspect.

try starting it with an initial value of 1 instead

/shrug

Ghoulish Delight 05-27-2010 03:00 PM

Python definitely indexes from 0. This is just a matter of the compiler/garbage collector optimizing code.


All times are GMT -7. The time now is 02:52 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.