| OLD | NEW |
| 1 Coding Style Guidelines | 1 Coding Style Guidelines |
| 2 ======================= | 2 ======================= |
| 3 | 3 |
| 4 These conventions have evolved over time. Some of the earlier code in both | 4 These conventions have evolved over time. Some of the earlier code in both |
| 5 projects doesn’t strictly adhere to the guidelines. However, as the code evolves | 5 projects doesn’t strictly adhere to the guidelines. However, as the code evolves |
| 6 we hope to make the existing code conform to the guildelines. | 6 we hope to make the existing code conform to the guildelines. |
| 7 | 7 |
| 8 Files | 8 Files |
| 9 ----- | 9 ----- |
| 10 | 10 |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 433 |
| 434 We follow the Google C++ guide for ints and are slowly making older code conform
to this | 434 We follow the Google C++ guide for ints and are slowly making older code conform
to this |
| 435 | 435 |
| 436 (http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Integer_Types) | 436 (http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Integer_Types) |
| 437 | 437 |
| 438 Summary: Use int unless you have need a guarantee on the bit count, then use | 438 Summary: Use int unless you have need a guarantee on the bit count, then use |
| 439 stdint.h types (int32_t, etc). Assert that counts, etc are not negative instead | 439 stdint.h types (int32_t, etc). Assert that counts, etc are not negative instead |
| 440 of using unsigned. Bitfields use uint32_t unless they have to be made shorter | 440 of using unsigned. Bitfields use uint32_t unless they have to be made shorter |
| 441 for packing or performance reasons. | 441 for packing or performance reasons. |
| 442 | 442 |
| 443 NULL, 0 | 443 nullptr, 0 |
| 444 ------- | 444 ------- |
| 445 | 445 |
| 446 Use NULL for pointers, 0 for ints. We prefer explicit NULL comparisons when | 446 Use nullptr for pointers, 0 for ints. We prefer explicit nullptr comparisons whe
n |
| 447 checking for NULL pointers (as documentation): | 447 checking for nullptr pointers (as documentation): |
| 448 | 448 |
| 449 <!--?prettify?--> | 449 <!--?prettify?--> |
| 450 ~~~~ | 450 ~~~~ |
| 451 if (NULL == x) { // slightly preferred over if (!x) | 451 if (nullptr == x) { // slightly preferred over if (!x) |
| 452 ... | 452 ... |
| 453 } | 453 } |
| 454 ~~~~ | 454 ~~~~ |
| 455 | 455 |
| 456 When checking non-NULL pointers explicit comparisons are not required because it | 456 When checking non-nullptr pointers explicit comparisons are not required because
it |
| 457 reads like a double negative: | 457 reads like a double negative: |
| 458 | 458 |
| 459 <!--?prettify?--> | 459 <!--?prettify?--> |
| 460 ~~~~ | 460 ~~~~ |
| 461 if (x) { // slightly preferred over if (NULL != x) | 461 if (x) { // slightly preferred over if (nullptr != x) |
| 462 ... | 462 ... |
| 463 } | 463 } |
| 464 ~~~~ | 464 ~~~~ |
| 465 | 465 |
| 466 Returning structs | 466 Returning structs |
| 467 ----------------- | 467 ----------------- |
| 468 | 468 |
| 469 If the desired behavior is for a function to return a struct, we prefer using a | 469 If the desired behavior is for a function to return a struct, we prefer using a |
| 470 struct as an output parameter | 470 struct as an output parameter |
| 471 | 471 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 Mandatory constant object parameters are passed to functions as const references | 507 Mandatory constant object parameters are passed to functions as const references |
| 508 if they are not retained by the receiving function. Optional constant object | 508 if they are not retained by the receiving function. Optional constant object |
| 509 parameters are passed to functions as const pointers. Objects that the called | 509 parameters are passed to functions as const pointers. Objects that the called |
| 510 function will retain, either directly or indirectly, are passed as pointers. | 510 function will retain, either directly or indirectly, are passed as pointers. |
| 511 Variable (i.e. mutable) object parameters are passed to functions as pointers. | 511 Variable (i.e. mutable) object parameters are passed to functions as pointers. |
| 512 | 512 |
| 513 <!--?prettify?--> | 513 <!--?prettify?--> |
| 514 ~~~~ | 514 ~~~~ |
| 515 // src and paint are optional | 515 // src and paint are optional |
| 516 void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src, | 516 void SkCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src, |
| 517 const SkRect& dst, const SkPaint* paint = NULL); | 517 const SkRect& dst, const SkPaint* paint = nullptr); |
| 518 // metrics is mutable (it is changed by the method) | 518 // metrics is mutable (it is changed by the method) |
| 519 SkScalar SkPaint::getFontMetrics(FontMetric* metrics, SkScalar scale) const; | 519 SkScalar SkPaint::getFontMetrics(FontMetric* metrics, SkScalar scale) const; |
| 520 // A reference to foo is retained by SkContainer | 520 // A reference to foo is retained by SkContainer |
| 521 void SkContainer::insert(const SkFoo* foo); | 521 void SkContainer::insert(const SkFoo* foo); |
| 522 ~~~~ | 522 ~~~~ |
| 523 | 523 |
| 524 If function arguments or parameters do not all fit on one line, they may be | 524 If function arguments or parameters do not all fit on one line, they may be |
| 525 lined up with the first parameter on the same line | 525 lined up with the first parameter on the same line |
| 526 | 526 |
| 527 <!--?prettify?--> | 527 <!--?prettify?--> |
| 528 ~~~~ | 528 ~~~~ |
| 529 void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, | 529 void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, |
| 530 const SkPaint* paint = NULL) { | 530 const SkPaint* paint = nullptr) { |
| 531 this->drawBitmapRectToRect(bitmap, NULL, dst, paint, | 531 this->drawBitmapRectToRect(bitmap, nullptr, dst, paint, |
| 532 kNone_DrawBitmapRectFlag); | 532 kNone_DrawBitmapRectFlag); |
| 533 } | 533 } |
| 534 ~~~~ | 534 ~~~~ |
| 535 | 535 |
| 536 or placed on the next line indented eight spaces | 536 or placed on the next line indented eight spaces |
| 537 | 537 |
| 538 <!--?prettify?--> | 538 <!--?prettify?--> |
| 539 ~~~~ | 539 ~~~~ |
| 540 void drawBitmapRect( | 540 void drawBitmapRect( |
| 541 const SkBitmap& bitmap, const SkRect& dst, | 541 const SkBitmap& bitmap, const SkRect& dst, |
| 542 const SkPaint* paint = NULL) { | 542 const SkPaint* paint = nullptr) { |
| 543 this->drawBitmapRectToRect( | 543 this->drawBitmapRectToRect( |
| 544 bitmap, NULL, dst, paint, kNone_DrawBitmapRectFlag); | 544 bitmap, nullptr, dst, paint, kNone_DrawBitmapRectFlag); |
| 545 } | 545 } |
| 546 ~~~~ | 546 ~~~~ |
| 547 | 547 |
| 548 Python | 548 Python |
| 549 ------ | 549 ------ |
| 550 | 550 |
| 551 Python code follows the [Google Python Style Guide](http://google-styleguide.goo
glecode.com/svn/trunk/pyguide.html). | 551 Python code follows the [Google Python Style Guide](http://google-styleguide.goo
glecode.com/svn/trunk/pyguide.html). |
| 552 | 552 |
| OLD | NEW |