I say "conventions" because these are not requirements of a programming language. Some languages don't let you start a variable with a number: 1variable might not work. However you could call this variable myVar or my_var or VARIABLE or Joe and all of those would work. (4/)
-
Show this thread
-
(Side note: when I first started programming, which was in JavaScript, I was very confused about variable names. One thing that helped was I actually started naming variables names like Joe and Harry to convince myself that arbitrary names didn't break my code.) (5/)
1 reply 0 retweets 0 likesShow this thread -
I felt that my own coding improved when I started to attempt to be more intentional about naming variables. I found Richard Johnson's The Elements of MATLAB Style extremely useful (not just for Matlab): https://www.cambridge.org/core/books/elements-of-matlab-style/8825411CE69013434DB0939780CFD907 … (6/)
1 reply 1 retweet 4 likesShow this thread -
Although in theory having consistent conventions makes code more readable by other people, I don't know how many other people look at my code. However when I look at my OWN code I find it much easier to read, and this has been hugely beneficial. (7/)
1 reply 0 retweets 1 likeShow this thread -
And, the impact has not only been on the "readability" but on my own thinking. So as I'm programming it helps me to think more clearly about what I'm writing, and (importantly) reduces confusion about variable types. (8/)
1 reply 1 retweet 1 likeShow this thread -
One example: I now tend to use longer, more descriptive variable names. Instead of s = '101'; I might use thisSubject = '101'; (9/)
1 reply 0 retweets 1 likeShow this thread -
A second example: I capitalize the first letter of structs. For a lot of functions I pass a "configuration" structure (which I think, but am not sure, I borrowed from
@fieldtriptoolbx) - in the old days I called this cfg or CFG. Now it's: Cfg = []; Cfg.blah = blah (10/)2 replies 0 retweets 0 likesShow this thread -
As long as your code works for your purposes do whatever you want. I've been helped a lot by trying to be intentional about naming in my own code. And, if you are sharing your code, consistency is one way to help other people understand it. (11/)
1 reply 0 retweets 3 likesShow this thread -
Final thought: I started with Matlab in ~2002 (and struggled a lot). I discovered The Elements of MATLAB Style in my first year as a faculty member (2012). There's lots of time to develop coding ability. Just keep at it! (12/12)
1 reply 0 retweets 8 likesShow this thread -
Replying to @jpeelle
Yup! This is why PEP8 is so good.https://www.python.org/dev/peps/pep-0008/ …
1 reply 0 retweets 1 like
I love this bit: "However, know when to be inconsistent -- sometimes style guide recommendations just aren't applicable. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don't hesitate to ask!"
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.