iOS Developing good programming etiquette ?

Will0827

macrumors regular
Original poster
Aug 11, 2008
155
17
I have been on and off again dabbing in programming since taking a app development course a couple of years ago. Since then i am just now starting to scratch the surface in understanding coding albeit tied to objective c and now swift. I watch and read as much as i can but nothing beats actually trying and failing. Basically my inquiry is how much and what you guys say is a choice of style and where would it be best to pick up on the standard practices, when it comes to writting code. For example im trying to get used to writting and reading curly braces being on the same line vs being on the next line. And another small example when to use switches versus a couple of if, else statements. From my reading i see as with any endeavor there are certain bad habits that form early on and without proper guidance become a hinderance as the more difficult to understand way of doing certain things doesn't register for beginners. Thanks

As an fyi i just now got the grasp of MVC and wrote a class and had it working in my view controller properly where as before i put all my code in the viewcontroller file, and wondered why i couldn't access the instance of an object, because the instance was local to the viewdidload method, and i couldn't figure out why what i had in mind wasn't working. That may provide some insight as to where im at, and what would possibly help. Thanks again in advance.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Coding styles develop over time and usually continue to evolve. My Objective-C style has continued to change over the years.

As a beginner you need to look at other people's code to see what they do. Pick what works for you though.

There are quite a few Objective-C style guides available. Mr. Google will help you find them. Don't feel that you need to follow a particular guide to the letter (unless you want to). But reading the guides will give you a good idea about why other people do certain things in their code. You can decide if you're persuaded by their explanations in their style guides.
 
  • Like
Reactions: moonman239

Smith288

macrumors 65816
Feb 26, 2008
1,105
711
Meh. It all get compiled into 1s and 0s. Pick a standard people use in various open source projects and go from there. As far as { placements? I still switch them up while thinking "shoot...do I always drop them down a line or not... oh well..."
 

mrxak

macrumors 68000
The thing you need to ask yourself is: "Is my code easy to understand and maintain?" At the end of the day, that is the only thing that matters when it comes to style. If what a style guide says makes sense 99% of the time, follow the style guide, but don't be afraid of that 1% case where writing your code in a different style improves readability and makes it easier to maintain. Style guides focus on an overall aesthetic. I feel it's a mistake to be slave to this aesthetic at the expense of the programmer's own intelligence and instinct.

There are always rules to follow, but it's up to the master in any particular craft to know when to break those rules.
 

Essenar

macrumors 6502a
Oct 24, 2008
553
186
Writing descriptive methods and variables isn't considered messy and obtrusive. This is because of Xcode's auto completion, importing and delegate abilities. If you write a UIButton action as editSettingsButtonPressed, you don't have to worry about it being really long because as soon as you go into your method file, when you type - in implementation and start writing "editS--" etc, it will auto complete the rest of the code so you can just hit enter and move forward with your code block.

Comments are usually not used. Explanatory method and variable names is good enough to communicate what you're doing.

Enumerations are great for TableView's because you can declare them once, and reference the cell type without having to constantly go back to Storyboard and ask "Which section was email again?" or so on.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.