When working on code from multiple authors, I often encounter the issue of curly-brace preference (same line vs new line). Is it good/bad practice or even a non-issue when it comes to matching the existing style vs using your own preference?
Does the situation change if you are adding new code to a Class vs modifying existing code? Finally, if style should be matched, how far should the match propagate? i.e. the file, the class, subclasses etc.
Example:
if(this)
{
doThat();
}
Vs.
if(this){
doThat();
}
Generally speaking, inconsistently formatted code will be more difficult to read and understand than code formatted in a style other than your own.
When working on an open source project, it is considered polite to match the style in use. For code you won't be sharing, either follow the style or run all the existing code through a reformatter.
It matters a great deal if a lot of code has been checked into a version control system. There will be a lot of noisy change in the history for a mere brace style change. I wouldn't do it for its own sake. You're in Rome....
If you will be sharing this, match his style for consistency. If not, do what you find comfortable. I personally prefer your style.
Try to talk with your coworkers and decide on a consistent style. Once you do that, write all new code in that style and convert old code if necessary. This is an issue specific to the project and the people working on it.
On the rare occasion that you can't come to a consensus, I wouldn't worry too much; there are far too many bugs in the world for people to be spending their time moving braces around. :D
It does not matter (code wise) where you place the curly braces, it is just a matter of preference. More experienced coders tend to put it on the same line, but I like to put it on the next line because it helps me see blocks of code easier. If you wish coding conventions to go as far as curly braces, then consult your team and choose one, but they'll probably laugh lol
There is nothing that irks me more than perusing code and finding numerous mismatched styles sprinkled throughout. If you are going to collaborate with someone on a program, than either explicit or implicit, standards should be used. Something as simple as a curly brace doesn't matter in the least, but when your project gets reviewed by management and you can't even get that one little thing matched up throughout it looks bad. Or if you are working on a personal project with friends and then decide to have others join, the project is going to start off looking unprofessional. I would say when working in a group like this, it is less about personal opinion, than it is about group standards.
Related
What are the syntactical features of current languages that prove problematic for screen readers or braille readers? What symbols and constructs are annoying to hear or feel? To the blind programmers out there, if you were to design a programming language which was easier for other blind people to work with, what would it be like?
Although it is a very interesting question, it is highly a matter of personal preferences and likings, so I'll answer as if you asked me personally.
Note: My working system is Windows, so I'll focus on it. I can write cross-platform apps, of course, but I do that on a Windows machine.
Indentation, White Spaces
All indentation-related things are more or less annoying, especially if the indentation is made with multiple spaces, not tabs (yes yes, I know the whole "holy war" around it!). Python did teach me to indent code properly even in languages that don't require it, but it still hurts me to write proper Python because of these spaces. Why so? The answer is simple: my screen reader tells me the number of spaces, and the actual nesting level is four times less. Each such operation (20 spaces, aha, dividing by 4, it is fifth nesting level) brings some overhead to my mind and makes me spend my inner "CPU" resources that I could free for debugging or other fancy stuff. It is a wee little thing, you'd say, and you'd be right, but this overhead is on each and single line of my (or another person's!) code I must read or debug! This is quite a lot.
Tabs are much better: 5 tabs, fifth nesting level, nice and well. Braille display here would be also a problem because, as you probably know, a Braille display (despite the name) is a single line of text, usually 14 to 40 characters long. I.e., imagine a tiny monitor with one single line of text that you pan (i.e., scroll), and nothing besides that. If 20 chars are spaces, you stay with only 20 chars left for the code. A bit more, if you read in Grade 2 Braille, but I don't know whether it would be appropriate for coding, I mostly use speech for it, except some cases.
Yet more painful are some code styling standards where you have to align code in the line. For instance, this was the case with tests in moment.js. There the expected values and messages should match their line position so, for example, the opening quote would be in column 55 on every line (this is beautiful to see, I admit). I couldn't get my pull request accepted for more than a week until I finally understood what Iskren (thank him for his patience with me!), one of the main developers, was trying to tell me. As you can guess, this would be completely obvious for a sighted person.
Block Endings
A problem adjacent to the previous one: for me personally it is very nifty when I know that a particular code block ends. A right brace (as in C) or the word end (as in Ruby) are good, indentation level change (as in Python) is not: still some overhead on getting knowing that the nesting level has abruptly changed.
IDEs
Sorry to admit it, but there is virtually no comfortable IDE for the blind. The closest to such an IDE is Microsoft Visual Studio, especially the latest version (gods bless Jenny Lay-Flurrie!), Android Studio seems also moving towards accessibility starting with version 2. However, these are not as usable, nifty and comfortable as they are for the sighted users. So, for instance, I use text editors and command-line tools to write, compile and debug my code, as do many blind people around me.
Ballad of the snake_case, or Another Holy War
Yet another thing to blame Python about: camelCase is far more comfortable to deal with then snake_case or even PascalCase. Usually screen readers separate words written in camelCase as if they were separated with spaces, so I get no pain readingThisPartOfSentence.
When you write code, you have to turn your punctuation on, otherwise you'll miss something really tiny and "unimportant", such as a quote, a semicolon or a parenthesis. Then, if your punctuation is on, and you read my_very_cool_descriptive_variable_name, you hear the following: "my underline very underline cool underline.... underline underline underline!!!" (bad language and swears censored). I tried even to replace underlines with sounds (yes, my screen reader gives such an opportunity), but the sounds can't be so well synchronized because of the higher speech rate I use. And it is quite a nightmare when dealing with methods and properties like __proto__ (aha, there are two underscores on both sides, not one, not three - well, got it right, I think!), __repr__ and so on, and so forth. Yes, you might say, I can replace the word "underline" with something really short like "un" (this is also possible), but some overhead is still here, as with white spaces and code nesting.
PascalCase is far better but it implies a bit more concentration, also, since we need to remember putting the first capital letter (oh, I'm too fastidious now, let it be PascalCase, but not those under... oh well, you got it already). This was the reason I gave up with Rust, btw.
Searching for Functions
As I have already told you, IDEs are not good for us, so text editor is our best friend. and then, you need to search for functions and methods, as well as for classes and code blocks. In certain languages (not Python this time), there are no keyword that would start a function (see, for example, C or Java code). Searching for functions in these conditions becomes quite painful if, for example, you do know that you have a logical error somewhere in the third or fourth function in the file, but you don't exactly remember its name, or you skim through someone's code... well, you know, there are lots of reasons to do that. In this particular context, Python is good, C is not.
Multiple Repeating and Alike Characters
This is not a problem per se, but a circumstance that complicates debugging, for example, regular expressions or strongly nested operations like ((((a + ((b * c) - d) ** e) / f) + g) - h. this particular example is really synthetic, but you get what I mean: nested ternary operators (that I love, btw!), conditional blocks, and so on. And regular expressions, again.
The Ideal Language
The closest to the ideal blind-friendly language as for me is the D language. The only drawback it has is absence of the word function except for anonymous functions. PHP and Javascript are also good, but they have tons of other, blind-unrelated drawbacks, unfortunately.
Update about Go
In one of his talks Rob Pike, the main developer of the Go language said that no one likes the code style imposed by the Gofmt utility. Probably, no one — except me! I like it, I love it so much, every file in Go is so concise and good to read, I'm really excited about the language because of that. The only slightly annoying thing for a blind coder is when a function has several pairs of parentheses in its definition, like if it is actually a struct method. the <- channel operator still gives me moments to think about what I'm doing, sending or receiving, but I believe it's a matter of habit.
Update about Visual Studio Code
Believe it or not, when I was writing this answer and the first update to it, I wasn't working as a full-time developer — now I am. So many circumstances went favorably for accessibility and me in particular! Slack, that virtually every business uses, became accessible, and so became Microsoft Visual Studio Code (again, gods bless Jenny and her team!). Now I use it as my primary code editor. Yes, it's not an IDE per se, but it's sufficient for my needs. And yes, I had to rework my punctuation reading: now I have shorter and often artificial names for many punctuation signs.
So, calling from end of January 2021, I definitely recommend Visual Studio Code as the coding editor for blind people and their colleagues. What is even more amazing is that LiveShare, their pair programming service, is also accessible! Yes, it does have some quirks (for now you can't tell what line in the file your colleague is editing if you're blind), but still it's an extremely huge step forward.
Is it bad to be semantic purist all
the time, at work? is it not achievable all
the time ?
when i saw code of any other
person/interviewee. I know selection
of element for a purpose is most
important thing.
what i should judge person ability
from his code; from a good written,
managed, optimized css or how he
wrote class and id names?
Or both every time.
Is it bad to be semantic purist all
the time, at work? is it not
achievable all the time?
Yes. Sometimes the tools doesn't work the way that you would like, and you just have to use something that does work. It's worth a little effort to make the code more semantically correct to make maintenance more effective, but at some point you just can't defend the development cost because the gain in maintenance that it would give is a lot less.
what i should judge person ability
from his code; from a good written,
managed, optimized css or how he wrote
class and id names?
Anyone can have bad habits or incomplete knowledge in some areas. You should rather judge a person on the ability to see the difference between good and bad code when presented with it, and for showing a certain interrest in getting it right.
It depends on what you mean by "semantic purist".
Is his code so bad that you MUST refactor it first before you can do any maintenance on it or even be able to understand what the heck it does? Then it's important.
If the code is not perfect by your standards but udnerstandable, AND can be maintained, AND the person seems receptive to your hints about ways to improve it - especially if those hints are accompanied by explanation of why the improvement makes the code X% more readable/stable/maintainable, it's not THAT important what their level of "purity" is now.
If the person is willing to spend extra week polishing their code to be semantically pure at the cost of shipping late, he's a net loss by a big margin.
To give a specific example for css, if someone will add a class to EVERY element on a page just because it "should be added", bad.
If they indicate that the class needs to be added to places X, Y and Z so that jQuery selectors perform 20% better than alternative solution, VERY GOOD.
Both actually contribute to different abilities. A great abstraction design in Classes and Properties will depict his ability to analyze things where as a well writted managed optimized css expresses that he is himself/herself an organized person. The later property is also very important.
Still I will go for the first property if the css is atleast presentable.
Are you in danger of setting up a false alternative? We can either choose class and identifier names carefully or we can write working CSS? Ideally I'd prefer someone who can do both.
What do you deduce about the likely quality of a person's work if their job application has serious misspellings? Like the misspelling the name of the company they are applying to! What do you deduce about a project proposal that mis-states the objectives of the project? A person applying for a SW security job who confuses "authentication" and "authorisation".
In the interview you are trying to determine from a very small sample of information the likely way a person will perform if they come to work for you. We need to factor in many factors such as the effect of interview pressure on some folks performance, and whether they are working in their native language. I don't see any absolute standards here, and no scope for simple either-or questions such as you pose.
Of course we need them to be able to produce code that works, that's the easy bit! Quality of code, and quality of other aspects of work also do matter.
The other day i stumbled onto a rather old usenet post by Linus Torwalds. It is the infamous "You are full of bull****" post when he defends his choice of using plain C for Git over something more modern.
In particular this post made me think about the enormous amount of abstraction layers that accumulate one over the other where I work. Mine is a Windows .Net environment. I must say that I like C# and the .Net environment, it really makes most things easy.
Now, I come from a very different background made of Unix technologies like C and a plethora or scripting languages; to me, also, OOP is just one, and not always the best, programming paradigm.. I often struggle (in a working kind of way, of course!) with my colleagues (one in particular), because they appear to be of the "any problem can be solved with an additional level of abstraction" church, while I'm more of the "keeping it simple" school. I think that there is a very different mental approach to the problems that maybe comes from the exposure to different cultures.
As a very simple example, for the first project I did here I needed some configuration for an application. I made a 10 rows class to load and parse a txt file to be located in the program's root dir containing colon separated key / value pairs, one per row. It worked.
In the end, to standardize the approach to the configuration problem, we now have a library to be located on every machine running each configured program that calls a service that, at startup, loads up an xml that contains the references to other xmls, one per application, that contain the configurations themselves.
Now, it is extensible and made up of fancy reusable abstractions, providers and all, but I still think that, if we one day really happen to reuse part of it, with the time taken to make it up, we can make the needed code from start or copy / past the old code and modify it.
What are your thoughts about it? Can you point out some interesting reference dealing with the problem?
Thanks
Abstraction makes it easier to construct software and understand how it is put together, but it complicates fully understanding certain issues around performance and security, because the abstraction layers introduce certain kinds of complexity.
Torvalds' position is not absurd, but he is an extremist.
Simple answer: programming languages provide data structures and ways to combine them. Use these directly at first, do not abstract. If you find you have representation invariants to maintain that are at a high risk of being broken due to a large number of usage sites possibly outside your control, then consider abstraction.
To implement this, first provide functions and convert the call sites to use them without hiding the representation. Hide the data representation only when you're satisfied your functional representation is sufficient. Make sure at this time to document the invariant being protected.
An "extreme programming" version of this: do not abstract until you have test cases that break your program. If you think the invariant can be breached, write the case that breaks it first.
Here's a similar question: https://stackoverflow.com/questions/1992279/abstraction-in-todays-languages-excited-or-sad.
I agree with #Steve Emmerson - 'Coders at Work' would give you some excellent perspective on this issue.
After spending a not-insignificant amount of time converting a page that used concatenated html, like
string output = "";
output +="<ul>";
foreach(MyClass item in MyItems)
{
output += "<li>"+item.Name+" - "+item.SomeProperty.ToString()+"</li>";
}
output+="</ul>";
literalPlaceHolder.Text=output;
to use the ListView control, I've just discovered that the original developer went back and converted the page back to using concatenated html. My personal feeling is that listviews and repeaters lend themselves to cleaner, more informative markup that can be edited by someone with less experience with C#, and that they are faster and use less memory. At the very least the page should be using a StringBuilder instead of a string. Anyone have a good argument for this? I have a feeling it's going to cause a major conflict when I bring this up.
I disagree with the answer above.
First on a technical point of view.
Using concatenated strings in the codebehind is clearly mixing the View with your Logic. If I would browse this application, I would wonder where the output html comes from, since the aspx (or ascx) would be empty.
Furthermore, if you are using controls like the Repeater and he is concatenating html code and just outputing it to the page, there will be no consistency between the different areas of your app, and it will just become a mess to know where to look at when a bug comes up, or when a feature has to be added.
I would suggest you simply ask him why he prefers to concatenate Html. What are his reasons to switch back your code to his way of doing without asking first.
I also disagree on a team-work point of view.
In a team, Communication is everything. Without communication, you're vowed to fail. Don't fear to communicate. when there is a question, you have to ask it and you have to make things clear. whether you win or he wins is not the point. the point is to understand eachother and to work as a team, together, not against eachother.
First of all, I think it's not very cooperative for another developer to just replace your code like that, with no discussion. You will definitely have to make a good case for your position if you want to prevail in this one.
I agree that the standard ASP.Net controls are easier for less-experienced developers to deal with, if that is a concern in your situation.
I'm not sure I agree with you about StringBuilder, which has often been the source of raging debates here and elsewhere. If your list is not lengthy, there may not be sufficient justification for a StringBuilder here.
One aspect that a seasoned developer might appreciate about this particular approach is that it is easy to step through and see exactly how each item is being populated. That isn't as easy with a ListView -- you'd have to add an event to catch the items being added, and then put a breakpoint in it.
And finally, I would encourage you to choose your battles carefully. This particular example is not a major design issue. If you foresee other, larger differences of opinion in the future, you might decide to start here with a smaller issue, to establish a way of resolving these kinds of conflicts with your fellow developer. Alternately, you could consider that this is not a big enough deal to fight about, and wait for something of major importance (and I doubt that you will have to wait long). Which way you choose to proceed depends upon the personalities involved.
Say you got an old codebase that you need to maintain and it's clearly not compliant with current standards. How would you distribute your efforts to keep the codebase backwards compatible while gaining standards compliance? What is important to you?
At my workplace we don't get any time to refactor things just because it makes the code better. There has to be a bug or a feature request from the customer.
Given that rule I do the following:
When I refactor:
If I have to make changes to an old project, I cleanup, refactor or rewrite the part that I'm changing.
Because I always have to understand the code to make the change in the first place, that's the best time to make other changes.
Also this is a good time to add missing unit tests, for your change and the existing code.
I always do the refactoring first and then make my changes, so that way I'm much more confident my changes didn't break anything.
Priorities:
The code parts which need refactoring the most, often contain the most bugs. Also we don't get any bug reports or feature requests for parts which are of no interest to the customer. Hence with this method prioritization comes automatically.
Circumenventing bad designs:
I guess there are tons of books about this, but here's what helped me the most:
I build facades:
Facades with a new good design which "quarantine" the existing bad code. I use this if I have to write new code and I have to reuse badly structured existing code, which I can't change due to time constraints.
Facades with the original bad design, which hide the new good code. I use this if I have to write new code which is used by the existing code.
The main purpose of those facades is dividing good from bad code and thus limiting dependencies and cascading effects.
I'd factor in time to fix up modules as I needed to work with them. An up-front rewrite/refactor isn't going to fly in any reasonable company, but it'll almost definitely be a nightmare to maintain a bodgy codebase without cleaning it up somewhat.