0
votes
5answers
41 views

How a programmers solve the dilemma of using old variables instead of new variables?

For example: ... some code int sizeOfSomeObject = someObject.length(); ... some code, sizeOfSomeObject is not need anymore now I need other int variable for other action(for example, for position ...
-2
votes
1answer
69 views

recursion Vs. Iteration - Pros & Con's [duplicate]

What (if any) advantages/disadvantages, does recursion have versus iteration? Is one better than the other? If so, why? Is one worse than the other? I'm looking to get a general pro's versus con's ...
0
votes
2answers
30 views

what is stl-style for merge two containers while alternating the elements?

What is an elegant way to do the following in STL-style rather then for(;;): Given p={1,2,3} and q={7,8,9}, i'd like to merge this to be pq={1,7,2,8,3,9}. one application is creating pq vector for ...
1
vote
1answer
42 views

Does JVM manage class code by function? Is splitting a large decision function effective on memory usage?

Problem In a server-based java solution we need a bigger lookup table with static values (about 300 kB but the data increases yearly with new values for the next year). Usually the table would be ...
5
votes
5answers
97 views

Does an else statement slow compile time/run speed? (In situations where one could be avoided)

On innumerable (well, numerable, but many) occasions, especially within a method/function of a class, I've been in a situation where I want to do a set of operations within a void-return function, but ...
2
votes
1answer
118 views

Simple indeterminate progress bar in Python [closed]

Even when I am afraid to be a bit off-topic, but I am not sure where else to ask this, sorry! I wish to build a **simple** indeterminate progress bar in Python there is a really valid progression ...
0
votes
4answers
60 views

append in a list in Python using result value or a function

are the both approaches equivalent from a point of view of performance and coding-style? def foo(n): return n*2 # case 1 with ".append(function())" mylist = [1,2,3,4,5,6,7,8,9,10] result = ...
3
votes
3answers
83 views

Are long variable names a waste of memory?

If I have an variable int d; // some comment. Will that be better than int daysElapsedSinceBlahBlahBlahBlah with no comment. It is more reabale, but will it waste memory?
0
votes
2answers
73 views

combine two loops in python

suppose to have two polygons p1 and p2, where p2 is completely inside p1 p1 = [(0, 10), (10, 10), (10, 0), (0, 0)] p2 = [(2, 6), (6, 6), (6, 2), (2, 2)] degree_of_contact = 0 xyarrays = [p1,p2] ...
0
votes
2answers
69 views

python - When function need to became a class

I am learning the use of class in Python. Typically I write several function to run my script, but recently i am writing using class. I am sorry for the basic question, but when is the limit to use a ...
1
vote
1answer
104 views

using @property to build a class in Python

I am not clear on the use of @property (advantages and disadvantages). I want to ask for some example using this class built with the help of Martijn. The data (in text format) always has a x,y, and ...
2
votes
2answers
44 views

Resolving how to give an attribute in a class in Python

I have the following class: class Point(object): __slots__= ("x","y","z","data","classification") def __init__(self,x,y,z,n=None): self.x = float(x) self.y = float(y) ...
3
votes
2answers
102 views

Using len() and def __len__(self): to build a class

Just curious, Is there any difference (advantages and disadvantages) between using len() or def __len__() when I build a class? And which is the best Python style? class foo(object): def ...
0
votes
1answer
67 views

Python: resolve problems with my Class [closed]

I have the following class def get_percentile(obs,*args): lstper = [] for arg in args: lstper.append(np.percentile(obs,arg)) return lstper get_percentile([1,2,3,4,5],25,50,75) ...
0
votes
1answer
41 views

how to build a function in order to process single iterable or two or more argument

i have the following function example (average of a list of number): def avg(obs): return (1. / len(obs)) * np.sum(obs) avg([1,2,3,4,5]) 3.0 I am interesting t understand how use a single ...

1 2 3 4 5
15 30 50 per page