Go to Post I have way too much time on my hands. - Brandon Martus [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #16   Spotlight this post!  
Unread 15-02-2006, 21:16
aaeamdar's Avatar
aaeamdar aaeamdar is offline
Post-A-Holic
AKA: Paul Dennis
FRC #1719 (The Umbrella Corp)
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Baltimore, MD
Posts: 231
aaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant future
Re: A few simple programming questions;

Quote:
Originally Posted by Keith Watson
I've seen bugs introduced when people use pre or post ++ at the wrong time.
An example? I'm curious.

Quote:
Originally Posted by Keith Watson
Even something as simple as always using parentheses to establish precendence instead of relying on operator precendence makes code much more understandable.
Some people think that there is somehow an advantage to cramming something into the fewest lines possible (ahem!). Sometimes it's necessary to optimize things even if these optimizations make things less readable. If your program does billions of mod 32 calculations, and you have some method

Code:
 
int mod32(int x)
{
     while (x > 32)
     {
            x -= 32;
     }

     return x;
}
This works and everyone should be able to tell what it does. I think there's also a modulus method in the C libraries, but I could be wrong. Anyway, the point is that this would probably be a fairly clear way of doing it. But if you were trying to reduce the amount of time your program takes (and it could take a while if you enter in large numbers and do millions of calculations) this is what you would want the method to do:

Code:
int mod32(x)
{
     return x & 31;
}
It's less understandable. Some people may not even know what the & operator does. An italisized description follows:

The & is a bitwise AND operation. In other words, it works with the ones and the zeroes. AND evaluates to true or one if cond1 and cond2 evaluate to one. Example: 7&11

7 = 4+2+1;
11 = 8+2+1;

0111
1011
____
0011


The bitwise operation works faster. It only works with powers of two (don't try x&10) but in those cases, it works. If you want, think about why (or PM me). Just draw it out.

However, oftentimes the best code for processing time is the most understandable too. Also, when you think about the speed of today's processors, unless you are writing code that /needs/ to run fast, there is not much point in optimizing.

[\END LECTURE]

That was rather off-topic, but I found it interesting. I hope you did too (or skipped over it).

Tat's all for now, folks. Tit for tat.
Paul Dennis
  #17   Spotlight this post!  
Unread 16-02-2006, 18:01
Oumonkey's Avatar
Oumonkey Oumonkey is offline
Master of the If statement
AKA: Josh Tyus
FRC #1555 (Pulse)
Team Role: Programmer
 
Join Date: Jun 2005
Rookie Year: 2005
Location: Monon, IN
Posts: 50
Oumonkey has a spectacular aura aboutOumonkey has a spectacular aura about
Re: A few simple programming questions;

Wow, Thanks for all the help. Although that last post hurts my head. But now, I think I have everything working. We are hooking up electronics now so I haven't been able to test anything, yet. But still, I'd give you all hugs, If I could, and a cookie if I could!
Danke!!!
Team 1555's only poor little programmer.
__________________
  #18   Spotlight this post!  
Unread 17-02-2006, 12:25
AUWarEagle#1's Avatar
AUWarEagle#1 AUWarEagle#1 is offline
Registered User
FRC #1611
 
Join Date: Jan 2006
Location: South Effingham
Posts: 4
AUWarEagle#1 is an unknown quantity at this point
Smile how to program a trigger

hi how are you, this is from team 1611. This is our second year in FIRST and i am new to programming. can you explain to me the process of programming the triggers? if it's possible, can you write one for me?? sorry for the inconvenience.
  #19   Spotlight this post!  
Unread 17-02-2006, 14:24
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: how to program a trigger

Do you mean the triggers on joysticks? ("Trigger" also has another meaning in software development circles.) What do you want them to do? Once we know that, we should be able to help you. (Try searching too. I believe what you need may have already been covered in some other threads.)
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How To Ask Questions the Smart Way Brandon Martus General Forum 8 27-03-2013 15:52
Programming laptops [527]phil Programming 24 22-08-2005 12:28
#1 The Journey of a FIRST Graduate: Questions Ken Leung General Forum 12 27-07-2005 18:24
Suggestion for Delphi Programming Posts Chris Hibner CD Forum Support 1 27-07-2005 10:02
Can You help us??? (programming questions) HuskieRobotics Programming 1 24-02-2004 21:19


All times are GMT -5. The time now is 11:45.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi