coding-style

Does using leading underscores actually cause trouble?

时光毁灭记忆、已成空白 提交于 2019-12-31 01:34:52
问题 The C/C++ standard reserves all identifiers that either lead with an underscore (plus an uppercase letter if not in the global namespace) or contain two or more adjacent underscores. Example: int _myGlobal; namespace _mine { void Im__outta__control() {} int _LivingDangerously; } But what if I just don't care? What if I decide to live dangerously and use these "reserved" identifiers anyway? Just how dangerously would I be living? Have you ever actually seen a compiler or linker problem

Elegant way to prevent namespace poisoning in C++

那年仲夏 提交于 2019-12-30 11:28:06
问题 Let's assume, Bob has wrapped his library into the namespace "bob", and Alice is going to make the whole namespace visible inside her own function by a single "using namespace bob", instead of "using bob::XYZ" for every single item: // This file is written by Alice: #include <iostream> // She uses Bobs library: #include "bob.hpp" int main(void) { // Import Bobs library and use it: using namespace bob; unsigned short value = 50000; bob::dump_as_signed(value); // Should not be possible without

Change the style of WinForm border?

若如初见. 提交于 2019-12-30 10:45:28
问题 Is it possible to change the style of a WinForm border? I know that if the border is removed, it takes away the functionality to resize the program. Therefore is there a way to change the style of it, but keep it resizable? 回答1: What you seek is not simple because the border is drawn by the operating system. However, there is a library on CodePlex that does make possible to do this very thing. Drawing Custom Borders in Windows Forms 回答2: First write this in the InitializeComponent(): public

Coding style of “if” statements [duplicate]

余生长醉 提交于 2019-12-30 08:54:02
问题 This question already has answers here : “Backwards” Conditionals in C [duplicate] (4 answers) Closed 3 years ago . Lately I've been noticing the style of some programmers who write "if" statements backwards. That is, in the test they put the constant value first and then the variable that they are testing second. So for example they write: bar = foo(); if (MY_CONSTANT == bar) { /* then do something */ } To me, this makes code somewhat difficult to read. Since we are really talking about

Coding style of “if” statements [duplicate]

被刻印的时光 ゝ 提交于 2019-12-30 08:52:14
问题 This question already has answers here : “Backwards” Conditionals in C [duplicate] (4 answers) Closed 3 years ago . Lately I've been noticing the style of some programmers who write "if" statements backwards. That is, in the test they put the constant value first and then the variable that they are testing second. So for example they write: bar = foo(); if (MY_CONSTANT == bar) { /* then do something */ } To me, this makes code somewhat difficult to read. Since we are really talking about

Not specifying control names in WPF… performance effect

点点圈 提交于 2019-12-30 08:29:07
问题 If you need to access a WPF control from the code behind, you need to supply a Name attribute to it in XAML. In many cases, you don't need to access controls from the code behind, since a lot of coding logic such as binding is better applied directly inside XAML. My question is: Is there a performance gain from not supplying the name attribute to controls? Or is it a good habit to give names to all controls on the page? 回答1: Yes there is definitely a performance gain from not supplying "name"

About the use of signed integers in C family of languages

眉间皱痕 提交于 2019-12-30 08:11:58
问题 When using integer values in my own code, I always try to consider the signedness, asking myself if the integer should be signed or unsigned. When I'm sure the value will never need to be negative, I then use an unsigned integer. And I have to say this happen most of the time. When reading other peoples' code, I rarely see unsigned integers, even if the represented value can't be negative. So I asked myself: «is there a good reason for this, or do people just use signed integers because the

About the use of signed integers in C family of languages

流过昼夜 提交于 2019-12-30 08:11:37
问题 When using integer values in my own code, I always try to consider the signedness, asking myself if the integer should be signed or unsigned. When I'm sure the value will never need to be negative, I then use an unsigned integer. And I have to say this happen most of the time. When reading other peoples' code, I rarely see unsigned integers, even if the represented value can't be negative. So I asked myself: «is there a good reason for this, or do people just use signed integers because the

how to make clang-format add new line before opening brace of a function?

戏子无情 提交于 2019-12-30 07:57:15
问题 I'm interested in putting an opening brace for functions (but not if statements and other contexts). For example void foo() { ... } Flamewars aside, is there a good rationale for not doing this? Although I use same-line open-brackets for if/else and smaller blocks, I think in this case visual organization of larger units of code (functions/methods/classes/structs) can trump perfect consistency. Moreover, how do I get clang-format to follow this style? 回答1: As the documentation says, invoke

Function name for creating something if it's not there yet

前提是你 提交于 2019-12-30 06:43:21
问题 From time to time I write a function that just creates something if it's not there yet and otherwise does nothing. Names like CreateFooIfNecessary() or EnsureThereIsAFoo() do work but they feel a bit clumsy. One could also say GetFoo() but that name doesn't really imply that foo may be created first and it only works if the function returns a handle/pointer/reference to foo . Can those of you more familiar with the English language come up with a better way to name these functions? 回答1: How