coding-guidelines | Coding guidelines for projects at Leapfrog | Static Site Generator library
kandi X-RAY | coding-guidelines Summary
kandi X-RAY | coding-guidelines Summary
Coding guidelines commonly followed at Leapfrog Technology.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Page layout menu
coding-guidelines Key Features
coding-guidelines Examples and Code Snippets
Community Discussions
Trending Discussions on coding-guidelines
QUESTION
I have a library currently structured as this:
...ANSWER
Answered 2019-Dec-09 at 21:56If that's really all you do, then it's not a breaking change. There is no possible way that any client code relying on the old design could be broken.
The second version, I'm not so sure. You'd be hiding the base method (you should use the new
keyword, by the way, to make your hiding intentions clearer), and that changes the way the method resolution happens at runtime. It could be fine (albeit really ugly) or it could mess something up.
EDIT: Actually, I just thought of a way client code could be broken, but that shouldn't be considered a breaking change, more like a curiosity, unless using reflection on your dll is something to be expected: any code using System.Reflection.TypeInfo DeclaredMethods
property or GetDeclaredMethods()
method would be potentially broken.
In any case, client code that uses reflection is supposed to be recompiled and potentially fixed when referenced libraries are updated.
QUESTION
I'm reading the C specification, which states in 6.5 Expressions
The effective type of an object for an access to its stored value is the declared type of the object, if any. If a value is stored into an object having no declared type through an lvalue having a type that is not a character type, then the type of the lvalue becomes the effective type of the object for that access and for subsequent accesses that do not modify the stored value.
Can anyone explain what this means? I've got a vague feeling that it has to do with pointers and malloc()
, but that's as far as I can get without help from a lawyer...
Update based on answer: Can I safely do this?
...ANSWER
Answered 2019-Jun-20 at 17:54When you declare a variable of a given type, it refers to an underlying object of that type, so the object's effective type is the type of the associated variable.
Where things get a little fuzzy is when malloc
comes into play. Memory returned from malloc
has no effective type. For example:
QUESTION
The TypeScript Coding Guidelines state
Use undefined. Do not use null
Having just read another article on ECMAScript, which advocates for null over undefined, I was wondering whether Microsoft’s or the TypeScript team’s rationale is known for this decision?
...ANSWER
Answered 2019-Jan-10 at 07:00No rationale is necessary for guidelines, the requirement could be chosen at random in order to keep the code base consistent.
As for this guideline, undefined
takes more characters to type but doesn't need to be explicitly assigned to nullable variable or property:
QUESTION
http://c0x.coding-guidelines.com/6.7.2.1.html:
1401 If the struct-declaration-list contains no named members, the behavior is undefined.
Does this mean that the following is illegal?
...ANSWER
Answered 2019-Jan-04 at 18:42Very little in C is illegal, meaning you cannot do it. Rather, many things are not defined by the C standard, meaning that, if you do them, the C standard does not say what will happen. Structures with no named members are such a thing.
C 2018 6.7.2.1 8 says, in part:
If the struct-declaration-list does not contain any named members, either directly or via an anonymous structure or anonymous union, the behavior is undefined.
If you need something to serve as an “unknown type” and do not want to use void
, then you can declare a structure whose tag is known but whose contents are not, as with:
QUESTION
Stateless React components should be named in PascalCase, so React can distinguish between native elements and components. Typescripts naming convention dictates that we should use lowerCamelCase or UPPER_CASE for the name of const variables.
How can I satisfy both (React and tslint)?
...ANSWER
Answered 2017-Sep-06 at 06:55I think you have two options here:
Use where appopriate comment like this
/* tslint:disable-next-line:variable-name */
to disable tslint warning at that particular line
Use class components instead of functional ones.
QUESTION
If you look here and here it says you should not prefix your member field variables.
But if you look at the source code for .net core all field variables are prefixed with _?
When you scaffold a Controller in Visual Studio 2017 it also generates fields with the _ prefix?
So something must be wrong here?
...ANSWER
Answered 2018-Oct-16 at 08:04The core variables are private. The guidelines state that "Internal and private fields are not covered by guidelines"
QUESTION
The C11 spec on enums1, states that the enumerator constants must have type int (1440-1441):
1440 The expression that defines the value of an enumeration constant shall be an integer constant expression that has a value representable as an int.
1441 The identifiers in an enumerator list are declared as constants that have type int and may appear wherever such are permitted.107)
However, it indicates that the backing type of the enum can be either a signed int, and unsigned int, or a char, so long as it fits the range of constants in the enum (1447-1448):
1447 Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type.
1448 The choice of type is implementation-defined,108) but shall be capable of representing the values of all the members of the enumeration.
This seems to indicate that only the compiler can know the width of an enum type, which is fine until you consider an array of enum types as part of a dynamically linked library.
Say you had a function:
...ANSWER
Answered 2018-Oct-08 at 20:58The complete definition of the enum
needs to be visible at the time it is used. Then the compiler will know what the size will be.
Forward declarations of enum
types is not allowed.
QUESTION
Question: What is the best practice for naming private properties in Typescript and should one as a rule create a “get and set” for that property?
Reading the following link gave me pause to what I thought would be a good practice for coding Typescript: https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines
I understand his qualifier to his coding guideline that this is not a prescriptive guideline, however, his convention on naming private properties brings up questions in my mind on proper encapsulation and use of private properties in Typescript. The convention I have been following is to name the private properties with the prefix of underscore and then create a get and set that I use to assign or get the value from that property. Back in Anders’ Delphi days that convention is what made it a property and not just another variable. That property gave it characteristic that allowed for tooling.
Example:
...ANSWER
Answered 2018-Feb-14 at 21:16Found the answer I was looking for:
https://angular.io/guide/styleguide
Properties and methods Style 03-04 Do use lower camel case to name properties and methods.
Avoid prefixing private properties and methods with an underscore.
Why? Follows conventional thinking for properties and methods.
Why? JavaScript lacks a true private property or method.
Why? TypeScript tooling makes it easy to identify private vs. public properties and methods.
QUESTION
As I read about naming convection in asp.net Here
Use Camel Case for variables and method parameters
So i should use camel case naming for variables and method parameters but I don't know why visual studio warn me about these names:
...ANSWER
Answered 2017-Dec-25 at 08:39use camel case for local variables and pascal case for class level variables like
QUESTION
Recently I've switched from pure node.js to Typescript. In Microsoft's coding guidelines for Typescript they want their contributors to use forEach
instead of loops. Literally everywhere I read that iterating with forEach is roughly 95% slower than iterating over a for loop.
Since a foreach loop looks much cleaner in most situations I wonder if they simply don't care about the performance (decision made in favour of readable code) or if there is another reason why I could forEach in Typescript?
Microsofts Coding Guidelines for Typescript: https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines
...ANSWER
Answered 2017-Oct-09 at 23:39Generally foreach is safer and is better for readability and maintainability. Each element is read only and so cannot be modified. It is also impossible to get index out of bounds exceptions. However if performance is of particular concern you might find that a for loop is more appropriate.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install coding-guidelines
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page