Hot answers tagged

51

Allowing people to ignore coding styles because of personal preference is a bad idea. The quote in your question seems to allow any developer to simply say "I'm not going to use this style because I don't like it." This goes against the whole point, which is getting everyone on the team to do things the same way for consistency and readability. I agree ...


13

Coding style, and style guides exist to help make code more readable. And readability exists to help with complexity. Hence ultimately whether or not to violate (I'd call it adapt) the coding style to match your organizational needs comes down to how much it helps make things understandable. Remember, everything, and I stress, EVERYTHING, from OO ...


9

As far as I can tell, the statement that confused you is a pragmatic compromise made in order for the guidelines to serve as wide an audience as possible. Depending on your specific context (more on that below) you may have an option to adjust it and make more efficient use of the guidelines. You see, guidelines refer to "strong personal objections" as a ...


6

Is coding style in organizations an optional thing? Organizations opt to have coding styles - there is no requirement to have the in the first place. So the quote you are reading addresses the biggest issue that I see regarding coding "style" and real superstar "hackers" - you bring a new guy on board and he writes code that will drop zombies and makes ...


6

If your class is too big and unwieldy when it's all in one place and you can easily see it all, what makes you think scattering it across multiple files and making it harder to correlate will be an improvement? Partial classes are essentially a hack to make it easier for generated code, such as that produced by the form designer, to work together with ...


5

In terms of speed of execution they are the same. The compiled/interpreted code is going to do a test if nodetype == 3. If yes it executes a return statement next. If no it executes the other return statement next. Both cases are going to execute a return statement next. In terms of stack usage, they are the same. In both examples shown, it only drops ...


5

Putting the default statement first will work technically, but is a very unusual idiom. IMHO that's because what you scetched above is not the typical "use case" for a switch/default block. It is much more common to use the default branch similar to an else statement, like switch (value) { case 1: potential_case1() case 2: potential_case2() case 3: ...


5

You could create your custom method for extracting Map values as an Either instance and use them in a for comprehension: implicit final class MapOps[A, B](self: Map[A, B]) { def getAsEither(key: A): Either[String, B] = { self.get(key) match { case Some(value) => Right(value) case _ => Left(s"Key not found: $key") } } } case ...


5

Something meaningful? Nesting lots of meaningless loop variables quickly becomes unreadable. Imagine seeing something like this embedded inside four levels of loops: do_stuff(i,j,k+4, l*i) and trying to understand what it does vs something like: do_stuff(row, col, height + 4, function_value * row) This is a simple example. A lot of this sort of logic ...


4

If there are four or more dimensions, then they represent something more than just cartesian (or other) co-ordinates, so just use a (short) word that signifies what each level actually is.


2

It is conventional in recursive functions to write the base case first. That means your first option. Your second option is testing for the inverse of the base case, which is confusing to read. Writing the base case first makes little difference in this particular case, but in the general case if you were to use pattern matching, or a switch statement, or ...


2

The correct answer is: C. None of the above. Option A: void fill_array(Array<Type>* array_to_fill); This is more idiomatic for pre-C++11 code where smart pointers were troublesome due to a lack of move semantics, and still continues to be the safer of the two options. The key here is the function does not "own" the memory: it performs one ...


2

Refactor the big function. It probably does several things repeatedly or nearly so, if it loads several "prefabs". Then, the logic needed for repetition can be put into other functions, which could open more possibilities for refactoring (one or more new classes for loading "prefab" types, maybe?). Moving the code to a partial class will only obscure the ...


2

This more of a psychological ploy instead of some literal interpretation of how best to manage coding styles. It makes the team/company/manager/leader less authoritarian. I would focus more on situational exceptions instead of personal. Regardless of the coding document, the goal is to make things easy to read. Confusing code should be addressed and altered ...


2

So, am I misunderstanding something from this document and the quote at the top of this question? Can people really just ignore coding style? It depends. The place I'm at currently has no style guide, and it's not a big deal. There are some slight variations between programmers, but not so much as to impact readability, discoverability, or consistency ...


2

Not much of coding in Python and its long time since I coded in C. For C programs, I used to prefer top-down, because that is how I design my programs. If a calls b, b is listed after a. I also used to have a header for each .c file that lists all functions in it and included in the .c file. I follow the same model in Java class methods now.


2

The difference between my_list = list() and my_list = [] is that list requires a namespace lookup, first in the module level globals, then in the builtins. On the other hand, [] is a list literal and is parsed as creating a new list from the language, which doesn't require any name lookups. So the literal is faster on object creation. Otherwise, ...


2

Based on your edits, your aiming for the right goal. There are many benefits to using a style guide, but the two most important in my opinion, are readability of code between team members, and lack of "silly" commits (like white space only, or extra lines and the like). To achieve your goal, your chosen (or created) style guide should be simple and easy ...


1

Wouldn’t it make sense to have an interface (Java speaking) OrderedSet and the classes BinaryTree and RedBlackTree implement that interface? If you are implementing a library and introduce the interface later, this will require a new major version. In this new major version, it could also be possible to rename the class OrderedSet to BinaryTree and ...


1

Addressing the question from a different perspective, I'd say that providing a domain-oriented abstraction may be the best answer. Rather than describing the properties (abstract or concrete) of the implementation, define an abstraction that is directly domain-relevant to its users, and limited to the specific capabilities they need. This means you provide ...


1

I've grappled with code style guidelines for years, as many others have on this forum. This includes both fighting style guides I find abhorred, and trying to encourage others to use style guides to rein in their style so it can be more readable as a whole. The corporation benefits from a common coding standard. There are many important things to consider ...


1

It doesn't matter too much what coding style people have, as long as they have a coding style. If a company insists on a coding style, they step heavily on the toes of about 49% of their developers. The problem is that a large number of developers don't mind much adapting their coding style to some prevalent standard in a company, but they mind very much ...


1

Wappalyser will not be able to see the backend code running on a remote server. If you are running your Django site locally, then it will be able to inspect and report on everything. or to put it another way, you do not have access to Youtube's backend server so you cannot tell anything about it or the technology it uses. You do have full access to your ...


1

If you're writing code that needs a library, the import for the library is necessarily less code than the code which uses said library. When you put the two together in the same file, it is more likely that changes in one will result in remembering to do the other. Particularly if your editor uses pyflakes to enforce PEP compliance and therefore notices ...


1

You have two options. Create seperate mywebsite.api and a mywebsite.app projects in your solution. Advantages Proper seperation of concerns. You can delploy updates to your api and your front end independently. Architecture of sites can be changed independently (i.e. you can update your api to run on asp.net 5 without affecting the website) Cleaner ...


1

Well, obviously you can seperate them into two solutions, add another project in solution, or have them in same project. I will tell what I would. IMHO, if you want to take advantage of Sessions in IIS and/or hide authentication process within API, write angular in Visual Studio as well. VS2015 has a pretty good integration(intellisense) with angular if you ...



Only top voted, non community-wiki answers of a minimum length are eligible