![]() |
|
Re: ** Python Support Thread **
And when you get to teach at MIT you may be able to do that too... Until then, learn how the debugger works like the rest of us just in case. :)
|
Re: ** Python Support Thread **
Heh, it doesn't surprise me a bit that an MIT Professor is saying something like that. When you're doing research, you probably don't have to worry much about memory management, error conditions, users, and all the other things that make us in the real world have to use debuggers.
|
Re: ** Python Support Thread **
They can also spend half a day typing print statements instead of producing code...
|
Re: ** Python Support Thread **
MIT is one of the most theory oriented schools in existence. I work with a couple of people that got their degrees there and they said, "If you really wanted to, and planned your classes right, you could graduate without writing any code."
|
Re: ** Python Support Thread **
And I can respect that because computer science is a valid and useful field.
But so is software engineering. |
Re: ** Python Support Thread **
I did watch the first lecture of the second class. According to them, computer science is not a science, nor does it deal with computers.
I ended up agreeing with the professor. Next time you talk to the MIT guys, ask them if they know how to use a debugger. :p |
Re: ** Python Support Thread **
Ah, the question of whether math is a science. That's an interesting one. Pointless, but interesting to debate I'm sure.
|
Re: ** Python Support Thread **
Quote:
|
Re: ** Python Support Thread **
Quote:
|
Re: ** Python Support Thread **
Quote:
|
Re: ** Python Support Thread **
Quote:
|
Re: ** Python Support Thread **
Quote:
another way to look at it: text editors are typewriters with a cursor, splitting and organising text automatically. they are the same thing, at an essence. right? |
Re: ** Python Support Thread **
Yup. I'd love to see a print statement that will let me pause the program, overwrite memory as I choose at runtime, then resume the program.
|
Re: ** Python Support Thread **
Python does have a nice interactive debugging console built in:
Code:
import code |
Re: ** Python Support Thread **
I about freaked out. I came across a problem where I had to return several values (320 to be exact) from one function, and I couldn't for the life of me figure out how to return more than one result. I was really mad at myself because I either did this before and completely forgot, or I "learned" to do this, but I forgot, but after some research, I found out that I actually never been exposed to this.
I found this SO thread inspiring, though useless because it talks about dealing with say two or three items: http://stackoverflow.com/questions/5...rom-a-function I think that this is an interesting problem set because it deals with some of the list/tuple questions people itt ask about, exposes my short-coming as a thinking programmer, and of course, introduces a complete headache. and on to the yucky spoil tag for #8: Spoiler:
|
Re: ** Python Support Thread **
I am not too ashamed to say I haven't done much with the debugger yet. I opened the thing up and saw
__main__ and other stuff and got intimidated. I guess the pressure hasn't been to strong since I haven't written a 10000000 line program, but I'll get to the tutorial on this soon enough. I posted that teacher comment tongue-in-cheek, obv. The other advice he gives is the walk away for two hours and come back with a fresh set of eyes, since if you are debugging for 1hr/58m, you aren't saving any time at all. I'm sure the interviewers and management would be very happy to hear that one. |
Re: ** Python Support Thread **
When I was in school for {gasp} COBOL it was very common to stare at a chunk of code for a long time not seeing the problem. Which usually was a missing piece of syntax. These were usually spotted on the first read through when someone else looked at your code. There is something to be said for fresh eyes. At work there is usually something else you can be doing instead of banging your head against the code.
|
Re: ** Python Support Thread **
It was a lot harder to spot syntax issues in the days before editors would turn our code into fruit salad.
|
Re: ** Python Support Thread **
False alarm on my issue. At least missing the obvious sometimes presents tons of new information (outside of showing how little I know). But still, i prefer pounding the keyboard like a robot.
|
Re: ** Python Support Thread **
dave,
not a ton of time so i'm not going to give your post a colonic or anything, but a few comments (some of which might even be useful): Quote:
Quote:
ruby has a simple and elegant way to deal with this problem. the sort() method returns an array containing the sorted elements. if you want to do the sort in place, you have sort!(). the ! notation is simple and consistent throughout the language, a beautiful thing. Quote:
Quote:
2. i'm not entirely clear on what you're trying to do but the consuming function wants a dictionary so your function should create and return a dictionary. not sure why you think you need to return multiple things; looks like you just return one thing: a dictionary. hth/prepared for flames from the python fanboys :p, tyler |
Re: ** Python Support Thread **
I don't always agree with the code style they give me.
For example, using the globals seems unneccessary to me: Code:
VALUE, WORK = 0,1I read all of it and just concluded that Python is for people who haven't discovered Ruby. :D As far as the dictionary issue. I over-thunk the idea and forgot YAGNI. |
Re: ** Python Support Thread **
Think of them less as globals and more as constants. Obviously this is python and their constant-ness is not enforced, but the ALL_CAPS name implies that the variables are constants and should be read only.
It may seem silly in small examples, but it does have value. In the future, when you decided to make some new piece of data be the 2nd element instead of work, you just need to edit your constant instead of find every instance of "subjects[*][1]". Oh and then there was that one time where you called the base variable something else. However, in general, I would not use lists like this at all. I am completely against using a list just because you can*. It leads to issues where order becomes import and and small changes can effect lots of code. If the data you are encapsulating is not a collection of things, you should find a better data structure. In this example a Subject class with a value and work property would be more explicit and easier to process. *Who can guess my opinion of Scheme? |
Re: ** Python Support Thread **
Quote:
|
Re: ** Python Support Thread **
Quote:
The two profs in this course are Lisp/Scheme programmers. This isn't supposed to be a 'how to program Python course,' but a 'how to program' course and this course is pretty list/tuple heavy. I guess that this is an okay way to present data, but I agree that this is likely overkill when working with the data. However, I was beginning to believe that list/tuple/dictionary comprehensions was the strong point of Python. The profs were talking about how Lisp deals with pointers and list comprehensions and what happens when there are lists inside of lists, and then what happens if values have variable length, and my mind about exploded. Python simplifies all of this. Take the attitude toward dictionaries when dealing with javaScript, which are called "associative arrays" in js: Don't do it. Obviously there is some controversy surrounding lists/arrays/dictionaries/tuples/..... and when/how to use them, but if a language is full of powerful features using expanded data storage types, it makes sense to me that the creators or handlers of Python created a large portion of the language's features with these data-types in mind. I don't know how accurate my thinking is on this. It could be that the profs are so used to using lists that they just generally default to it, or it could be that lists are challenging to use so they make you work with them to make you think harder about the problems. Right now, they are talking about memoization, which, as far as I can tell, is just a dictionary of values. If I decide to dive into Python and buy that 1600 page book on the language, then those questions will likely be answered, but right now, I do the lemming (read: student) thing. Not sure how much further into this language I would like to go. For some reason, I simply can't enjoy coding it, no matter how much it's promoted as fun to code. |
Re: ** Python Support Thread **
Quote:
Quote:
Quote:
Code:
1Quote:
[php]def fib(int n): if (n>1): return fib(n-1) + fib(n-2) return n [/php] I found the 1000th Fibonacci number and it took me a minute to calculate. If I want to find the 2000th number, it will take me at least a minute because you have to have calculate all the numbers before it. Even more basic, calling fib(1000) twice in succession would take 2 minutes. But I already know the 1000th number, so I really don't need to recalculate it. [php] memo = {} def fib(int n): if (n in memo): return memo[n] if (n>1): result = fib(n-1) + fib(n-2) memo[n] = result return result return n [/php] The function is only slightly more complicated (3 extra lines) and has the advantage of returning faster the more often you use it. The first call to fib(1000) still takes a minute (actually a little longer). But if you call fib(1000) again, it is just a hash-table look up to get the answer. The downsides are that the initial call will take longer because of the extra work and you use lots of memory. For now, you are just learning the method, so it doesn't matter. When you get to a point where you will actually use it, you will have to decide what is the best balance between recalculating values and storing old values in memory. |
| All times are GMT -4. The time now is 03:50 PM. |
|
Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Copyright © 2008-2020, Two Plus Two Interactive