-11

I cannot understand for whom Dart style-guide was written?

Dart Style Guide

Term PREFER form this guide:

"PREFER guidelines are practices that you should follow. However, there may be circumstances where it makes sense to do otherwise. Just make sure you understand the full implications of ignoring the guideline when you do"

Now one of the main practices that often discussed and, of course, we should follow it:

PREFER using var without a type annotation for local variables.

In short words, use type annotation in function body not recommended (except some very specific situations).

But when I look into source code of the Dart SDK I often see just the opposite.

Just one sample from many other similar.

runtime/lib/collection_patch.dart

Example:

void operator []=(K key, V value) {
    int hashCode = key.hashCode; 
    List buckets = _buckets; 
    int length = buckets.length; 
    int index = hashCode & (length - 1); 
    _HashMapEntry entry = buckets[index]; 
    while(entry != null) {
      if (hashCode == entry.hashCode && entry.key == key) {
        entry.value = value; 
        return; 
      }
      entry = entry.next; 
    }
    _addEntry(buckets, index, length, key, value, hashCode); 
  }

Why Dart team used type annotations for local variables instead of var?

mezoni
  • 10,684
  • 4
  • 32
  • 54
  • 2
    Add a ticket to the Dart issue tracker (https://code.google.com/p/dart/issues/entry). Though this looks like a minor issue and I'm sure they have more productive things to work on. This does not look like a SO question. Either the code was written before the style guidelines or one (or several) of the developers on the Dart team does not follow the guidelines. – ronag Feb 10 '14 at 11:36
  • @ronag Quality assurance in Dart always was considered as the minor issue. This is not a secret. Also this recommendation was added in July 2012. Against this recommendation Dart SDK code looks like developers so long forgotten about it. Although the size of the files small and changes therein introduced regularly. I wonder how they are seen through the eyes of those who are responsible for the quality assurance in their team? Or do you think that the quality is already enough even if the software does not crashed every day? – mezoni Feb 10 '14 at 13:00
  • I couldn't care less if the Dart SDK code uses type annotation or not in its internal code. It is not a question of quality but of style. As a professional developer I have to work with different coding styles on a daily basis and I have no problem with it (especially if it is internal code) as long as it is readable. – ronag Feb 10 '14 at 13:30
  • 1
    @ronag Dart is a scripting language. When we debug our scripts we were forced to look at the source code from the developers. Everyday. Everyday. As for me this looks in the Editor Debugger as not the best practice for me. Or it makes me think "Maybe my source code is wrong, if my code looks not like the code that written by the authoritative people in stable version of software that I use? – mezoni Feb 10 '14 at 14:11
  • @ronag Especially for you, if you do not know: http://en.wikipedia.org/wiki/Coding_conventions Coding conventions are a set of guidelines for a specific programming language that recommend programming style, practices and methods for each aspect of a piece program written in this language. These conventions usually cover file organization, indentation, comments, declarations, statements, white space, naming conventions, programming practices, programming principles, programming rules of thumb, architectural best practices, etc. **These are guidelines for software structural quality.** – mezoni Feb 10 '14 at 15:09
  • @ronag So, your comments: "It is not a question of quality but of style" is a wrong conclusion which only confirms that "in Dart web platform development process is absent as such a thing as quality assurance". – mezoni Feb 10 '14 at 15:14
  • Just because the Dart SDK uses a **different coding convention** internally than what **you** expect does not necessarily mean that the code quality is lower. If you work in industry you will notice that even within the same product different project teams use different coding conventions, which does not mean that one team produces better code than the other. I have nothing more to add to this discussion. – ronag Feb 10 '14 at 15:29
  • @ronag Overall quality of this entire software product is lower. Overall quality consist not only from your empirical "code quality". What are measure of code quality? What are measure of sofware quality? See my updated question. I wrote this especially for you and them who think that "Though this looks like a minor issue and I'm sure they have more productive things to work on". – mezoni Feb 10 '14 at 15:45
  • @ronag your words: "I have nothing more to add to this discussion." Very sensible move. There are different types of programmers. Some people write code because they getting money for this work. Others write code because it is their calling and they also getting for this money. Both are programmers, but the quality of the original product somehow different. – mezoni Feb 10 '14 at 15:55

1 Answers1

5

I cannot understand for whom Dart style-guide was written?

It was written for Dart programmers. Why? Because..

As we build up an ecosystem of Dart code, it’s helpful if it follows a consistent coding style. A dedicated style guide for Dart helps us make the most of the features unique to the language and makes it easier for users to collaborate.

And it is up to each programmer or team whether or not to follow these guidelines, which are just a suggestion.

ronag
  • 49,529
  • 25
  • 126
  • 221