Tag Info

New answers tagged

0

C: var = ((a = foo()), b = bar(), baz(), a + b); Using the comma operator to perform multiple operations, but return the right most expression. Can use used in macros for eg, growing an array and assigning a value (and many other things of course). #define ARRAY_DECLARE(arr) \ int _##arr##_count = ...


12

No, there is no unique code formatting standard. What makes you professional is to comply with those guidelines that your workplace has established. A professional understands that computer code must primarily be useful for other humans to read (and only incidentally executable by computers), and therefore agrees to participate in a standard shared at ...


5

No, but there are some coding conventions and programming styles (notably indent style). Each project or community may have its own conventions and styles. As an example, look into GNU coding standards In practice, studying the source code of some free software will teach you a lot.


6

No, there is no universal standard for how code must be formatted. Code formatting standards can be a topic of fierce debate because most of it centers around personal opinion. As a result, nearly every open source project or company uses a different standard and they may have multiple standards if more than one language is used.


2

The main reason to use interfaces is explained in the dependency inversion principle ( the D in SOLID ). High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions(***). The goal of this is decoupling the higher level from specific ...


2

If you're using a language where classes must be hard-coded into the code (e.g. Java/C#) then it might make sense to use an interface in case you ever want to change the implementation of Behavior that gets passed to ClientA or ClientB without recompiling. This usually happens when you want to unit test some code by providing mock implementations of ...


1

Yes you can [re]write programs without break statements (or returns from the middle of loops, which do the same thing). But you may have to introduce additional variables and/or code duplication both of which typically make the program harder to understand. Pascal (the programming language) was very bad especially for beginner programmers for that reason. ...


1

Put all integers from 0 to NxM-1 into an array, shuffle that array randomly and pick the results one after another (mapping to row/column could be anything trivial like row=idx mod M , col=idx/M). A good shuffle algorithm is Fisher-Yates shuffling, see here.



Top 50 recent answers are included