Various
When I write code, no matter what language I’m writing in, I always follow a particular set of rules regarding formatting and naming:
- All class names should be noun phrases, e.g. Car, Dog, Circle. When a class name is composed of more than one word, UpperCamelCase should be used, e.g. DatabaseConnection, ActiveRecord.
- All method names should be verb phrases, e.g. write(), destroy(), play(). Method names should use lowerCamelCase for concatenating multiple words, e.g. dealCards(), computeValue().
- All interface names should be adjectives ending in -able, preferably derived from verbs, e.g. Cloneable, Countable, Iterable. If the behavior described by the interface is not easily described in such a way, use of a noun phrase is acceptable. Interfaces, like classes, should use UpperCamelCase.
- All variable names should be noun phrases and should use lowerCamelCase. Constants should be written in ALL_CAPITALS with underscores.
- Braces belong on individual lines and should be lined up with the statement they are associated with. If the braces only enclose a single line of code, write the statement all on one line: if (true) { doSomething(); }
- Protected and private members should be prefixed with an underscore: _privateHelper();
- Optimal line-length is 80 characters, with a maximum of 120 characters.
- Prefer block comments over single-line comments. If there is no single-line comments, put the comment directly above the line it relates to if it is longer than a single phrase. Short comments may be placed at the end of the line they refer to, with several tabs of spacing to visually separate the comment from the code.
Sometimes I stray from these guidelines. When I write PHP, I tend to put the opening brace of control statements on the same line as the statement. When I write in Ruby, I use underscores instead of CamelCase. When I write in C#, everything except variables uses UpperCamelCase.
Coding standards are very important, I feel, and make reading someone else’s code a lot easier. As an example, I’ve read Adam’s code on occasion and find that it’s very messy, especially regarding his comments.
I’ve been reading through my C# book and am really liking the language and .NET as a whole. The platform is really nice and offers a lot of really cool features. If only Microsoft weren’t such assholes regarding its licensing, I would think .NET could easily overtake Java as the premier cross-platform programming environment. Too bad MS insists on charging lots of money when it comes to letting third parties implement .NET on platforms other than Windows. Here’s hoping that Mono can mature and catch up to all of .NET’s recent innovations. If Mono can make a full working implementation of .NET, and then maybe abstract WPF and all of those other proprietary extensions Microsoft has in such a way that other third (fourth?) parties can write bindings of similar services to those interfaces, that would be awesome. I’m not entirely sure if that would actually work, though. As long as the method calls match and connect to similar services, I think that would be fine. If, say, the WPF interface was rewritten to call GTK or Qt widgets, then I would imagine that a WPF application would be able to run just the same on Mono as on .NET. I really have no idea if it’s that simple.
I really wish PIC taught Java instead of C++. While I understand that it’s a good idea to have a background in C++ because the language is still widely used in a lot of industries and fields, I think Java is a much better language and offers a lot more, at least in terms of OOP and standard libraries, than C++. I also think Java is easier as a whole to learn.
And then the CS classes could define special libraries that students would use in their code. There’d be an overarching UCLA library; then each class would have its own library underneath that; then there would be libraries for that class’s project code and lecture demo code. So, the code for the demos presented in Lecture 5 of PIC 10A might be contained in ucla.pic10a.demo.lec5, or something. The code for the Tic-tac-toe assignment might be contained in ucla.pic10a.proj.tictactoe. If I were a CS teacher and I could do stuff like that, I definitely would.
In other news, I’m thinking of acquiring a mess of DS and Wii games over the course of the next few days. I have my eyes set on Geometry Wars for both the Wii and DS, and on Planet Puzzle League for DS, and on Prism for DS. I pretty much play the DS strictly for puzzle games and save the RPG’s and action games for the bigger console.
Grah it really does make me mad that UCLA doesn’t have an undergraduate TA program. I would really like to TA Ling 20 and even PIC. I don’t know if I’d really like to be a tutor, though that might be similar. I would have to look into that, though, and see what kinds of freedoms you have as a tutor. I’m not sure if I’d even get students. I was also looking into how to become a lab assistant at the PIC lab, but that seems to be closed to people in the department, which sucks.
If everyone spoke Sindarin, that would be so awesome. I would feel so awesome and so amazingly cool every time I spoke, it would probably be too much for me to take. Why did Tolkien have to die before finishing documenting the languages? Now we’ll never know how to properly conjugate the Sindarin verb.