tags:

views:

1021

answers:

32

I suspect that many of us didn't initially learn programming from a class, but picked it up on our own. What are some bad habits you picked up from your first language?

+10  A: 

goto statements

Chris
I'm not sure I'd classify this as a bad habit, if the language had no alternatives. If you kept using them after you moved to a language that had a concept of procedures, then yes :)
Thorarin
+2  A: 

I started programming in BASIC (MICROSOFT BASIC 1.0) on a Dragon 32, and it was really easy to spaghetti code (ON x GOTO, GOSUB...).

I will never forget my Computer Science professor in the first year at University humoring the endless chase of goto in BASIC code on the blackboard, it hurt a bit thinking I've done that ;)

Now more than 25 years have passed, I hope I put that behind me definately... :)

Manrico Corazzi
Any reference to the good old Dragon computer makes me happy :)
Ola Eldøy
A: 

My first language was JavaScript (unless you want to count HTML...). It was great to learn because it's such a forgiving language, but it also set me up for some really bad habits that still trip me up occasionally.

In particular, the fact that JS doesn't require a semi-colon to terminate each line. I still frequently have to go back and add semi-colons to my PHP code after making a small change...

Another biggie, compounded by the fact that PHP shares this "feature," is weak typing. Oh, how I wish C# would just know to call the damn .toString() automatically when I'm spitting out some label or message...

Asmor
I occasionally do the reverse: labelSomething = textBoxSomething2.Text;
Nazadus
How about the fact that label.ToString() returns "{System.Windows.Forms.Label}"
Joshua
+5  A: 

My first language was Sinclair Basic (on the 1K ZX81). A few highlights of the language included:

You had to use line numbers, which meant program flow inevitably revolved around the dreaded GOTO statement. It took me a while to grasp how a programming language without line numbers could work!

String variable names could only be 1 character long. That's right, one alphabetical character. But as RAM was limited to 1K, you couldn't afford to use longer names anyway. Hence variables always tended to be X, Y, A, B, C etc.

Again, because of limited RAM, the main thing you learnt was that readability was of secondary importance to terseness - the less characters you used, the better.

See this beautiful ZX81 manual.

Dan Diplo
Very nice manual!
Peter Štibraný
+5  A: 

Well, technically my first programming language was TI-BASIC on the TI-83 calculator. We had flow control, but it felt rather inconvenient, because for a long time I didn't know how to have multi-line if statements. So goto it was. It didn't use line numbers, but it did only allow two-letter labels, so I had to cram as much meaning as I could into two letters to keep track of what label did what. But that's not the kicker:

For variables, we could only use a single letter, or we could make a list, but it could only have a short name (which could never really describe all the elements I stuffed into it), or we could make a matrix, which was even more confusing. All of those could only be numbers. If we wanted string data, we had a few string variables, but no real way to manipulate them. Now, obviously the simple variables only had 26 values (A-Z), but we did have an unlimited number of lists. But for matricies we only had A-J (or so - I can't remember), and for strings we only had 10 of them. And you couldn't add more.

But the real problem with all of this was that all three of these kinds of variables were completely global - I could run a program, and if that program used the variable A in it, I could see the value of A when the program was done. And if you weren't careful, that value of A could muck up your program the next time you run it!

We didn't even have files, so I can only miss the lack of any file I/O in retrospect.

Chris Lutz
What pissed me off about the TI-83, was that the only way to use lower case letters directly, was to insert for example a Sin() function, and then delete some if you needed an i or an n :)
Thorarin
When I "graduated" from the TI-83, I was using what amounted to a @_ array ala Perl for argument passing. Scope was a pain....
Paul Nathan
Yes! I spent so very many hours in math class programming in TI-BASIC back in the day.@Thorarin: press alpha twice on the 83+ or 83+se, I think.
alberge
@Thorarin - I lived in the days of MirageOS, which allowed your calculator to type in lowercase. It was great, until I lost it and couldn't maintain the lowercase text I had written.
Chris Lutz
Community wiki'ed before I whore any more reputation from this one.
Chris Lutz
+6  A: 

My first real programming language was Visual Basic 3.0. Sometimes, when I'm creating controls on an ASP.NET page, I default to Hungarian notation for the controls, e.g., btnSubmit or txtUserName.

Robert S.
I do that too, force of habit.
Martin
Is it a bad habit to name things like btnDate and lblData? I would think that adds to clarity.
Josh
I think that UI components is one of the few places, where Hungarian notation is helpful and in order. I use it myself for WinForms and WebForms.
driis
I've used it a lot for UI controls in .NET myself. Especially because there is often a label that goes with just about any control, and you want to distinguish between the two. Postfixes can get annoying as well, so I'm still in two minds about this really.
Thorarin
Prefixes in controls cause intellisense to group them all together. Without this, the controls get buried in a mound of other items in the intellisense list.
Robert Harvey
I do that for controls as well, I would not consider it a bad habit.
Ed Swangren
I consider it a bad habit. I don't need to see all my buttons in a list. I'm more interested in the functionality. Consider btnTransferCase vs transferCaseButton.
Robert S.
In a typeless language like Basic it can be helpful. The problem is when you move to a language with an actual type system, and still keep doing it. That's what makes it a bad habit.
T.E.D.
A: 

BASIC on the C64.

bad habits? none, except that it took me some time to learn something different, not due to lack of skills, just because of lack of an alternative environment (I had an Amiga 500, then Amiga 1200, and I was not able to find compilers for them. Internet was not yet an option at that time)

Stefano Borini
+5  A: 

It took me a while to stop using strcpy and char myString[256] in C++ instead of the std::string class.

Pete
+1 for char array. Now add non-use of vectors and you're golden!
Hooked
+4  A: 

On the goto riff, I'd have to say my first language (Visual Basic) error handling gave me a

On Error Goto LineLabel

view that gives me bad habits when I do exception handling.

David in Dakota
Dangit, I just posted this, then read what your answer.
Martin
A: 

Hungarian-esque notation from Javascript.

Because it's all duck-typing in JS and there isn't anything like a Visual Studio to help you inspect and refactor, it encourages you to name your variables according to their intended use - I still think this is one of the few valid use-cases for sys-Hungarian.

Prefixing objects instances with "o" is still a curse I slip into with C# (and hastily correct) from time to time.

annakata
For me, an "o" prefix usually means this variable is declared on the stack.
Joshua
+2  A: 

I learned Hungarian Notation from VB3. It stuck with me for years, and finally about four years ago I kicked the habit.

JP
+2  A: 

Not my first language by far... but when I'm working in C#, I still occasionally catch myself writing:

int someArray[];

instead of

int[] someArray;

Not very impressive as bad habits go, but I think I've gotten rid of just about all the real bad habits by now.

Similarly, I sometimes forget the new keyword and wonder why intellisense isn't working for my constructor.

Thorarin
A: 

Everything gets a class (from Java).

Took a while to realize how to structure things nicely.

Paul Biggar
+11  A: 

Sitting long hours at computer :-(

Peter Štibraný
The OP said "bad" habits, silly...
Chris Lutz
+1  A: 

I wouldn't call it a disadvantage, more of a stumbling block, but learning procedural programming using Basic and Pascal originally made the transition to object-oriented programming waaaay harder. It meant an initial period of writing procedural programs in an OO language like Java...

Jon
A: 

The worst things I did in my first language, which was Apple Integer BASIC, were using GOTOs and global variables. I can't call using GOTOs a bad habit with me because I was ready to be rid of them by the time I had access to a language which provided an alternative, which was Apple Pascal. However, it took me some time to figure out how to write a program with minimal use of global variables, so I would say the over use of globals qualified as a bad habit.

Greg Graham
+9  A: 

The only really bad habit I got from BASIC that had to be unlearned later was an excessive dependence on global variables. At the time they just seemed so much easier than dealing with scoping.

I did learn a lot more bad habits from BASIC, but I also learned from sad experience why they were bad, and not to do them.

Good examples would be: goto-ghetti, when to and not to use subroutines, and the importance of planning ahead.

Oh, and the importance of off-site backups:

My parents used to think it was funny to send my baby sister into my room to wake me up on Saturday mornings. One day after failing she instead got hold of one of my tapes (TRS-80's initially used cassette tapes instead of floppies or hard-drives), stuck her finger inside, and started to gleefully pull out yards and yards of the magnetic tape. That tape contained all the personal BASIC programming projects I'd been working on for the last year. Suffice it to say that in short order actions were taken that made everyone in the family mad at everyone else. It did work to wake me up though...

T.E.D.
+1 for global variables. I got into the habit of using one global variable for all loop counters, or two if loops were sometimes nested. The fact that some function needed to specify "for Loop2 := ..." for no immediately apparent reason always bugged me, but as you can imagine, that was hardly the only problem with this approach...
Edmund
A: 

I don't know if I learned really bad habits from QBASIC. I worked out structured programming on my own, as well as the needed memory structures for argument passing. I hadn't learned how to use subs, so everything was IF...GOTO. My code was very structured by the time I moved on to C++; it just didn't use very advanced concepts. :-)

Paul Nathan
Hmm, and you never bothered to open any of the `QBASIC` examples? I mean, come on... Gorillas! :P
Thorarin
Nibbles and Gorillas FTW!
Will Bickford
QBASIC 1.1 wasn't very good. Also I wasn't very smart, I suspect. Possibly it was because I was 14. I found QBASIC 5 after I got on the 'net and learned about abandonwares, and my tiny teenage head was *blown*.
Paul Nathan
A: 

Mixing things up in the same function.

The language was BASIC, and it didn't have functions. I did "functions" with gosub. I would gosub to line 10000 or 20000 and write the "function" there. Since this was a pain in the ass, for small stuff I didn't actually make the gosub.

I lost the habit a while ago. Now I get nervous when a function serves more than one purpose.

Daniel Daranas
+2  A: 

Mutable state.

EDIT: Let's elaborate some... Most of the mainstream languages default to mutability. They encourage a programming style that promotes side-effects, which makes it hard to reason about the program and makes writing concurrent programs hard (because of the need for locking). In many cases it's possible to write better programs through a more functional approach, where things default to immutability and no side-effects. If you anyways need to use an object oriented or procedural language, knowing functional programming lets you write better programs in those languages, even if they do not support functional programming natively.

Esko Luontola
Please elaborate.
JAB
I am assuming the poster is now working with a language like Erlang that has no mutable state, thus avoiding many of the common concurrency pitfalls of other languages.
Toby Hede
Toby Hede is right. I'm right now moving from object oriented languages more into functional languages and trying to learn a new ways to think. Right now I'm learning Scala and Lisp, after which probably Haskell and Erlang.
Esko Luontola
Thank you for the elaboration, Esko.
JAB
A: 

My first language was C, was obsessed with pointers. Used it for everything.
Moving to C++, pointers produced some pretty weird results in objects.
In C# I miss them.

lune
+5  A: 

Constantly complaining about how this task could have been so much easier in my first language.

(Python)

Sean O'Hollaren
A: 
  • bad indentation
  • non consistent function, class, and variable names
  • debatable: not declaring types
dassouki
+1  A: 

Not tidying up after myself. Actually this is a recent bad habit for me with more and more garbage-collected languages. Got bitten recently because some COM objects weren't being garbage collected when my process had finished. Wouldn't have been a problem if I'd released them myself.

LRE
+2  A: 

Really poor exception handling practices. Exception handling is so important and I never did grasp that in the early days.

marcc
+5  A: 

Many things:

  • Soda addiction
  • Bad vision
  • Insomnia
  • Wrist pain
  • Difficulty converting to OOP
  • Difficulty thinking in OOP
  • Writing good and efficient algorithms that people in OOP dislike
  • Thinking in procedural programming
  • Listening to heavy metal while coding
  • Arguing with myself
  • Talking to myself in code
  • Thinking that everything in nature can be proven by code

...(the list goes on)

Secko
Writing good and efficient algorithms that people in OOP dislike -- haha, vengence!
Joshua
I liked that too
Ed Swangren
+1  A: 

I wish I had to handle memory management myself in Turbo Basic, where I first started as a kid. This way I could have learned C sooner.

Plus, I would be much more grateful for the wonders of garbage collection when I first met it.

leolobato
+1  A: 

For a long time I named all my interfaces IFoo and IBlah, thanks to a long time spent with COM.

Toby Hede
That's not a bad one, it's a GOOD habit!
Moayad Mardini
A: 

My first programming language was Microsoft's COMMODORE BASIC V2. Line numbers, GOTO statements, variables limited to 2 character names, abysmally slow ... it was all around pretty awful. So the one thing it taught me was "ignore what they gave you, and find a better way". I taught myself 6502 assembly from the hardware reference manual. It was more flexible and orders of magnitude faster, and to do anything fun on the C=64 you needed a million PEEK/POKE statements so it wasn't actually much worse in terms of readability anyway.

When I went to college, they were teaching C++ and (later) Java. It made me want to poke my eyes out, so I taught myself Lisp for fun. And boy did that get me in trouble: once you know Lisp, it's really hard to get yourself to want to write Java for some class. (Hey, what's REDUCE in Java 1.1? ...you're shitting me.) I survived Data Structures by doing my homework first in Lisp (so I could understand it), and then porting to Java (which was required). I have no idea how anybody else learned computer science, writing in a language like Java: it was so painfully verbose the important ideas were all hidden.

Is that a bad habit? I still don't know. These days when I've interviewed, I write Lisp in interviews (or maybe as low-level as Python or Ruby). Curiously, the companies I want to work for don't care if I know Java, but they love that I taught myself Lisp and assembly. And even when I have to write lower-level code, like C#, it looks a lot more like 1996 Lisp than 1996 Java.

Ken
+1  A: 

Programming in C++

Sounds like trolling but that's the way I feel about it now and I'm trying to break the habit.

+1  A: 

Not so much my first language, as my first programming environment -- writing FORTRAN at a teletype has left me with the bad habit of pounding hard on the keyboard.

Steve Gilham
A: 

I started with FutureBASIC back in 1995 or so. Everything was hard-coded (recursion escaped me completely until about the past year or so), I didn't know how to draw from other source files, and I didn't see the difference between FN userFunction and GOSUB, so I did GOSUB for everything.

Kaji