|
fletcher posted:Is it more common to write variables as someVariable or some_variable? I can't decide which to use. I like using someMethod() instead of some_method(), so I'm thinking it would make more sense to use some_variable. Match whatever your language/environment uses. If neither of those give any guidance, just be consistent.
|
# ¿ Feb 27, 2008 03:29 |
|
|
# ¿ Apr 29, 2024 02:55 |
|
Triangulum posted:TI BASIC question. I wrote my first program for my 83 that solves the quadratic formula. The problem is that my program gives decimal approximations instead of exact value when dealing with square roots. How do I program it to show exact values? code:
|
# ¿ Feb 27, 2008 22:23 |
|
6174 posted:Interesting. I remember just opening the files in a text editor when I used to play with programs on my TI-86 and then 89. Maybe it was the linking software allows you to view the programs?
|
# ¿ Feb 28, 2008 00:35 |
|
Don't think we have a bash scripting thread yet, and at any rate I'm not any good with it... What does -a mean in a [ ] expression? Googling for it is kind of a pain, and the bash resources I found were no help. edit: Never mind, found it; it's a logical and. It just looked strange because of the context I saw it in. Incoherence fucked around with this message at 03:10 on Feb 29, 2008 |
# ¿ Feb 29, 2008 02:57 |
|
dougdrums posted:So I was (not now, earlier) and programming and thinking about the finally statement. Is there any god drat reason for the finally statement? The only situation I see using finally in is if I didn't want to put a catch statement after a try which is a horrible practice anyways. And even if I did want to do that, couldn't I just use catch { } instead? code:
|
# ¿ Mar 2, 2008 07:00 |
|
ShoulderDaemon posted:Easy. All I've done is generated the sets in a sorted order, by building them piece-by-piece and never adding an element to a set if there is already a higher element in that set.
|
# ¿ Mar 8, 2008 19:59 |
|
ShoulderDaemon posted:Well, then it's not an input set, it's an input list, and you can do it by explicitly passing around the list of remaining elements, and chopping off prefixes of it. Or just keep the list out of band, and use an input set of integers from zero to (length of list)-1, then use those as indexes into the list. code:
Now that I look at it, you could solve that by not recurring on c, since b will necessarily return a superset of c. In other words, you'd need to add to ShoulderDaemon's algorithm that if the current element is equal to the previous element, don't recur.
|
# ¿ Mar 9, 2008 06:50 |
|
Alternative answer, which might work for some applications:code:
|
# ¿ Mar 27, 2008 19:16 |
|
ShoulderDaemon posted:Uhm... a sorted array is a balanced binary tree. The top node is the index closest to the middle, which you can get in constant time as long as you know the highest index, the left subtree is all indices before it, and the right subtree is all indices after it.
|
# ¿ Apr 4, 2008 03:37 |
|
nbv4 posted:and no, using radio buttons instead is not a proper solution. But back to your original question: logical-XORing a bunch of poo poo together just tells you whether an odd number of them are true. Easiest way to find out if more than one is true is just to assign a value (0, 1) to each and add them up.
|
# ¿ Apr 5, 2008 08:48 |
|
gotly posted:I'm taking a data structures class and we designed and implemented our own linked list. Now I'm trying to use the actual integrated LinkedList function in Java and I must be blind but I can't find the basic Next function that goes to the next item in the list in constant time. Explanation: Your question assumes a composite list (or a C style linked list): that is, each LinkedList object represents one node (say, with a first and rest, or with a data and a next). Java's LinkedList is the whole list in one object. So Java collections, and for that matter C++ STL collections, use "iterators" to represent the idea of sequence. You get the iterator, then whatever sequence-dependent things you want to do you do to the iterator. (Or you use foreach, but foreach doesn't solve all your problems.)
|
# ¿ Apr 28, 2008 10:05 |
|
fletcher posted:If I have a class with 3 members: id, name, parentId, and I want to print out the hierarchy like:
|
# ¿ May 2, 2008 21:29 |
|
fletcher posted:Sorry, I want to print the tree from the parents down
|
# ¿ May 2, 2008 23:58 |
|
darfur posted:I've searched the web for this, but can't really find a good answer. Consider the Java List interface: http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html You can see that among the implementations give there are ArrayList, LinkedList, and Vector. So anything that takes a List, and uses the List methods, can be called on any of these implementations. From a consumer's point of view, if they just want to get some data, the fact that ArrayList.get() and LinkedList.get() behave entirely differently under the hood is irrelevant. Another example: event handlers. All event handlers for a given event implement the same interface, but they may (and hopefully do) have different behavior, and you may have multiple different event handlers for a particular event. Incoherence fucked around with this message at 20:22 on May 7, 2008 |
# ¿ May 7, 2008 20:20 |
|
csammis posted:Huh? Event handlers (callbacks, whatever you call them in your language) are methods, not interfaces. The fact that you can have multiple event handlers for a single event has zilch to do with interfaces, it has to do with how events are implemented in your architecture. I was trying to think of an example where you would have multiple implementations of an interface and want to hold them all in a list and run them all in sequence, without using the one on the project I work on (I can't figure out a good way to generalize/anonymize it).
|
# ¿ May 7, 2008 23:08 |
|
darfur posted:In MEAT TREAT's tree, for the insert function, would it just take an INode as the parameter, and then you could pass it any class which inherits the INode interface and that class' specific implementation of insert would be what gets called? That is my understanding as to how an interface would work there, is this correct? Would you have to make sure you don't link different types of INodes together or is that what this enables you to do? (Insert yammering about the C++ virtual keyword here, but if you're talking about interfaces you assume the methods are virtual. Also insert yammering about how this is actually an instance of the Composite Design Pattern, and that if you're in academia there are all sorts of neat things you can add to this like the Visitor Pattern.)
|
# ¿ May 9, 2008 00:36 |
|
Tomed2000 posted:I'm not, just a student right now. I was having a conversation with a professor and he claims that 90% of the industry programs in a UNIX environment and I thought that was pretty inaccurate.
|
# ¿ May 30, 2008 23:27 |
|
Vanadium posted:I for one would rather sit down and start coding instead of memorizing Visual Studio stuff that stands between the program in my mind and the program-to-be on the computer.
|
# ¿ May 31, 2008 05:00 |
|
|
# ¿ Apr 29, 2024 02:55 |
|
N.Z.'s Champion posted:I guess it just sounds like an easy optimisation that could result in shorter/clearer code. Is it not? Could it make your code shorter? Possibly, but this is sometimes in conflict with making it clearer. Could it make your code clearer? Many optimizations don't, and since you don't know how this would be done, it's difficult for you to say. The XOR trick probably works in more languages than tuple-unpacking in Python, but it has a significant effect on code clarity (what the gently caress are all of these ^=s doing in my code), and as an optimization it's fairly negligible.
|
# ¿ Aug 26, 2008 00:17 |