| To: | REALbasic Network Users Group <realbasic-nug at lists dot realsoftware dot com> |
|---|---|
| Subject: | Coding Conventions/Style Tips Questions |
| From: | Chris Little <clittle at renlearn dot ca> |
| Date: | Fri, 4 Jan 2002 10:23:33 -0600 |
|
Hi all, I am an experienced C++ programmer and the company I work for has decided to use RB for a new project. Some of the coding guidelines that I use for C++ will work well for me in RB but I am wondering about others. In particular I don't want to write in a style that will affect performance (although I know that writing for clarity should be a priority over performance since our instincts are so often wrong about what is truly a bottle-neck in code). I was reading Theo Smith's web site, in particular the section on Speed/Code size tips, http://www.elfdata.com/programmer/tips.html. Very interesting and informative but I have some questions about some of his tips. 1. Is there really a difference in this code? if mybool = true then -> if mybool then
2. I had planned on defining one variable to a line, a practice that saves some bugs in C++ and should improve readability. Theo claims that dim s as string, p as string, q as string Should be written as dim s, p, q as string I would have thought that the compiler would make these lines equivalent. In fact writing dim s as string
should be equivalent too. There is another tip that suggests I should look for unused variables in dim statements and remove them. Doesn't the compiler strip these? 3. Don't return 0 / "" / nil / false unless you have to if whichByte <= memsize then
-> if whichByte <= memsize then
This tip seems error prone. I try to follow the one return point rule to simplify reading of code. i.e. dim aResult as integer
I would have expected little or no speed/code size difference between these three versions. 4. I tend to write methods and functions that do one thing. This leads to a lot of small pieces of code. Is there much overhead in function calls? 5. Get objects to deal with themselves somewin.someeditfield.text = "a"
-> somewin.somemethod sub somemethod()
Although I use the second style anyways, I'm surprised that there is much of a speed/code size difference. I guess what I am really asking is what is the current state of the RB compiler? Does it dead strip code and variables, constant propagation, common sub-_expression_ reuse, etc... Can anyone suggest other sites that I should look at for information like this. Chris PS. Theo I hope you don't take this negatively. I'm just surprised at some of the information that you provide. |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | lasso tool, Stefaan Degryse |
|---|---|
| Next by Date: | Re: lasso tool, Thomas Reed |
| Previous by Thread: | lasso tool, Stefaan Degryse |
| Next by Thread: | Re: Coding Conventions/Style Tips Questions, Erich Rast |
| Indexes: | [Date] [Thread] [Top] [All Lists] |