Tag Info

New answers tagged

-1

I implemented yet another C++ dependency injection framework, which recently was proposed for boost – https://github.com/krzysztof-jusiak/di – library is macro less (free), header only, C++03/C++11/C++14 library providing type safe, compile time, macro free constructor dependency injection.


3

RAII doesn't necessarily mean you have a fully working object. It means you have a fully constructed object that is ready to work. So if your object needs an initialisation call to set its state, that's fine - its nothing to do with RAII that ensures you have an object that is possible to fill with state (ie its not half-built in some uncertain state). I ...


0

As long as the guess is consistently high, your algorithm performs well by roughly halving the guess. Once you have made a low guess, the algorithm severely deteriorates in performance. By doubling after a low guess, you are guaranteed that the next guess will be too high. Now, the +1 factors come into play (especially the one after halving), which let you ...


0

The more sophisticated algorithm is definitely more efficient: it requires logarithmic time vs. linear time to find the value. Here is a description of binary search; that's basically what you have reinvented.


1

If encoding depends on previous fields, then MyFastMessageEncoder::encode is obviously non-const as it changes the observable state of the instance - calling it twice won't give the same result, therefore the state of the instance has changed, therefore it should be non-const. Otherwise it seems a bit odd that you have, in the FieldEncoder, both a costly ...


0

I think that any algorithmically non-trivial project will be ok. You could consider doing -e.g. with GCC MELT- a static analyzer which would compute (or overapproximate) the complexity of simplistic programs. BTW this would be quite ambitious and challenging, and you'll learn a big lot. Remember that algorithms are on papers, but programs are source code. ...


0

Console applications may seem boring but they are essential to the development of the programmers ability to think of solutions. The basics of programming are always overlooked these days with the shiny stuff. I still use console applications a lot to test out ideas before building the high-level stuff on them. Once you have become good at the low-level ...


1

Data/Object Anti-Symmetry As others pointed out, Tell-Dont-Ask is specifically for cases where you change the object state after you asked (see e.g. the Pragprog text posted elsewhere on this page). This is not always the case, e.g. the 'user' object is not changed after it was asked for its user.address. It's therefore debateable if this is an appropriate ...


2

Introducing new language features and extensions, most of the time, require new language keywords or syntax changes. In addition, its essential to name these keywords for their intended purposes so as to help programmers memorize the new features. Fortunately, for that purpose, new language version/standards contain a list of code-breaking changes that you ...


10

The C++ standards committee is full of smart people that are fully aware of the amount of existing code and the consequences of introducing new keywords. One of the aims of the committee is to keep as much existing code as possible working unchanged and that certainly plays a large role when deciding to add new keywords and how to name those keywords. To ...


0

Yes, Brainbench and CPPGM are commonly accepted. There are some of addtional certifications related to framewoks, e.g.: http://qt.digia.com/Resource-Center/Qt-Certification/ But emploers (especially in c++ positions) are looking for skills and exrepience rather than for certificates.


1

The biggest flaw is that your enumerator is similar to the C++ concept of an iterator, but doesn't follow the interface for an iterator. This means that your enumerators can't be used in conjunction with algorithms that are based on iterators (i.e. all algorithms in the standard library and in Boost). See the answer by @giantskin for an alternative.


6

It's probably simpler and more straightforward to just use a single template class that's compatible with iterator conventions: template <typename T> DataIterator { public: T &operator* () const { return *m_node; } DataIterator &operator++ () { // get next node... return *this; } DataIterator &operator-- () ...


0

What you are trying to do is likely similar to the router that is sitting in my home: it has dedicated functionality but needs a web front end for configuration and status reports. However, the approach that router vendors take is to implement an operating system on the device, usually Linux or even QNX, an embeddable Unix-work-alike. This allows you to ...


0

I don't think you actually want CGI, but just about every other way a Web server runs programs would seem to suit your purpose. CGI is pretty much tied to the file system. Each request starts a process with redirected standard input/output and a set of environment variables. You don't want that. FastCGI parses requests and passes them to another process ...


1

Desktop OpenGL and OpenGL ES share a lot of similarities. The older OpenGL, prior to programable shaders, is somewhat similar to ES v1, in which both relied on a fixed-function rendering pipeline (i.e.: just the C-API). GL ES 2 and above is a lot more like the modern desktop GL, since it requires the use of shaders and other modern rendering practices like ...


0

string::find actually returns the first position of the argument sequence in the string. So in your case, "Hi", returns position 0, which by definition is not true. You can fix the program as follows: #include <iostream> #include <string> using namespace std; string name; string input; //Possible Questions string c_hi ("hi"); string c_bye ...


3

Of course there's value. It just depends on whether the value is enough to offset the cost. If you regularly program Kernel modules, device drivers or high-performance, lockless algorithms that rely on hardware-specific atomic primitives, then sometimes assembly language is your only choice. If you want those sort of programming tasks to be available to ...


4

I think one of the values of assembly languages today that is overlooked is the didactic value. I would contend that an assembly language is the best entry language for someone who has never programmed before. Why? Because it is simple and bare. In assembly you have basically three elements: Registers, opcodes and memory addresses. Learn how to mix-and-match ...


5

Assembly was never a mainstream language. You learn it for the same reasons that people learned it in the 80s/90s, and before that: it's close to the metal. Learning assembly language Teaches you how the machine works, and Gives you access to the best possible performance (in theory). I say "in theory," because it doesn't come without a cost. ...


4

NO! Just imagine the confusion that will occur if somebody #include's that header, not knowing your trick, and elsewhere in their file they have a variable or function called "me". They would be horribly confused by whatever inscrutable error message would be printed.


11

this is (like nullptr) a constant pointer; the pointed data is const if and only if this appears in the body of a const member function. You cannot change a constant pointer, like you cannot change a constant literal like 23. So assignment to this like this = p; // WRONG is prohibited for the same reasons assignment to nullptr is forbidden: nullptr = ...


4

<stddef.h> is a 100% standard header file in C++, that provides the type ::size_t. As a bonus it also is standard in C. Very nice if you're writing a header file for a library with a C-compatible interface, using #if __cplusplus / extern "C" {. Note that the usual arguments about namespaces and naming collisions don't apply, as the Standard allows ...


16

Please don't do it! I am trying to cope with a large code base where macros are all over the place to save typing. The bad thing about redefining this to me is that the preprocessor will replace it everywhere even where this is not in scope/does not apply, for instance a stand-alone function, your fellow colleage might have a local variable called me ...


4

Statically linked executables don't need this redistributable. You create statically linked executable by switching the runtime type from "Multi-threaded DLL" to "Multi-threaded" (compiler option /MT instead of /MD). It is subject to the following limitations: All libraries the executable is linked to have to be compiled with the same setting. So if you ...


80

No, it is not. Mind the programmer who will maintain your code several years from now long after you've left for greener pastures and follow common conventions of the language you use. In C++, you almost never have to write this, because the class is included in symbol resolution order and when a symbol is found in class scope, this-> is implied. So just ...


37

So, you want to create a new language. Then do so, and do not cripple C++. There are several reasons not to do it: Every normal coding standard will suggest to avoid macros (here is why) It is harder to maintain code with such macros. Everyone programming in C++ knows what this is, and by adding such macro, you are actually adding a new keyword. What if ...


23

I suggest not to do this. This gives a reader which is not familiar with your macro a big "WTF" whenever he sees this. Code does not get more readable when inventing "new conventions" over the generally accepted ones without any real need. using this-> everywhere is too noisy and ugly That may seem so to you, maybe because you did a lot of programming ...


1

If I'm writing code on the client side, I don't know which of the variables I pass to a function might be changed and which I can expect to remain the same without an explicit knowledge of the parent function declaration. This is as it should be. When you call an API, you should know what you are calling and why. You should also know what the function ...


0

The differences between references and pointers have been extensively discussed, sometimes even here. That discussion probably shouldn't be re-started. But the other question - "Why not have everything as X or Y?" is easily answered. C++ gives you both options as a matter of principle, because you might want to use X, but you also might want to use Y. In ...


1

You pretty much answered the question yourself, and in a way that confirms my own experience: A python wrapper is better in all accounts except for speed and memory efficiency. You are not telling us what sort of application is that so you'll need to carefully weigh how important those factors are for you. In my experience, most of the time they matter very ...


-2

There are various level of embedded platforms using C as programming language ( of course it is your freedom to use assembly language at any time ) For 'Level' I am talking about the Internal SRAM and ROM resource level for a system. These platforms sometimes are resource constrained ( e.g. some 8051 platforms only have 128 bytes of User SRAM ). It is ...


0

There are some C++ or C libraries to send email (using SMTP): VMIME, libsmtp, etc. You could also find IMAP libraries And you could write C++ web applications, e.g. using an HTTP server library like libonion or wt, or making it a FastCGI client. You can do HTTP client processing using libcurl However, most people prefer coding web app in e.g. PHP. But you ...


2

From the comments I see that your "half-duplex" refers to the fact, that you should not operate on the same SSL object from different threads at the same time (or use explicit locking) and thus cannot use SSL_read and SSL_write at the same time from different threads. While most protocols are request/response and thus don't need parallel read and write the ...


8

You should use the separate compilation model of C++ to your advantage. C++ allows you to define a class without using a header file, so you can just define Fast in the same source file as where you have the definition of Process. To avoid name clashes with other units that might also have a (different) class Fast, you can wrap it in an anonymous namespace. ...


8

I can see three viable options here, where from a design perspective I find the bottom one most attractive. One is to indeed use your approach, perhaps with operator() to avoid redundancy. Another option is to define the class inside the function itself (this is allowed now). However, chances are you may need the class later, and honestly I doubt that ...


12

Let me put it this way. Does it seem like something C++ would do? C++ is replete with gotchas and undefined behavior, but in this one instance, it helpfully validates a parameter for you? Every other "safer" language you know throws an exception if you try to do anything with a null pointer, but the unsafest language you use just handles it cleanly? It's ...


0

There are two interesting things to note here. First, this is a common pattern for checking each of the low-order 4 bits of an integral value. The if condition is met if the corresponding bit is set. For the value 2 the bit pattern is indeed 0010. The other more interesting question is why the (int) cast? Apart from the bad style of using C-casts in C++, ...


2

These if-statements check if a specific bit of value is set. The hexadecimal value 0x4, for example, has the 3rd bit from the right set to 1 and all other bits set to 0. When you use the binary-and operator (&) with two operants, the result will have all bits set to 0 except for those bits which are 1 in both operants. So when you do the calculation ...


5

Each number can be expressed as value = b0*2^0 + b1*2^1 + b2*2^2 + b3*2^3 + ... with each b being either 0 or 1 (these are the bits of the representation). This is the binary representation. The binary AND (&) takes each of those b pair wise and performing AND on them. This has the following outputs: 0 & 0 = 0 0 & 1 = 0 1 & 0 = 0 1 & 1 ...


1

I don't think having a bunch of printlns is a design issue at all. The way I see it is that this can clearly be done with static code analyzer if it is really a problem. But it is not a problem because most people don't do IOs like this. When they really need to do lot of IOs, they use buffered ones (BufferedReader, BufferedWriter, etc..) when the input is ...


1

While the performance is not really an issue here, the bad readability of a bunch of println statements points to a missing design aspect. Why do we write a sequence of many println statements? If it were just one fixed text block, like a --help text in a console command, it would be much better to have it as a separate ressource and to read it in and write ...


1

Enums are a good idea If you'll provide this code via dll (good idea for me), I'd recommend not to change them into enum class and not no throw the exception, because these are C++ only features, and users will be not able to use your dll in C# for example If these enums will be used as a real register address (or offset) it would be better to initialize ...


-1

From a c# perspective K&R might be a great book on c ... i recently read it in an attempt to brush up on c. I have to say the code in it makes my eyes bleed (when having a c# hat on). In c# the current style is to make everything clear and not ram 4+ statements into one. If you want to learn c# this is not the place to start. I cannot recommend a book ...


3

Another answer gave an excellent overview over how you'd nicely encapsulate the row-oriented storage and give a better view. But since you also ask about performance, let me address that: SoA layout is not a silver bullet. It's a pretty good default (for cache usage; not so much for ease of implementation in most languages), but it's not all there is, not ...


1

What you have described is an implementation problem. OO design is expressly not concerned with implementations. You can encapsulate your column-oriented Ball container behind an interface that exposes a row- or column-oriented view. You could implement a Ball object with methods like volume and move, which merely modify the respective values in the ...


5

Firstly, let me agree that K&R is a great place to start with the C family. It is a really wonderfully written book. Importantly, it is quite concise. Be aware that C++ is much more closely related to C that C#, although C# does borrow heavily from both. Java in fact does the same, and indeed C# followed from Java. You can't learn C# or C++ just using ...


1

In higher level languages like C and C++, this is less of a problem than in Java. First of all, C and C++ define compile-time string concatenation, so you can so something like: std::cout << "Good morning everyone. I am here today to present you with a very, " "very lengthy sentence in order to prove a point about how it looks strange " ...


25

There are two 'forces' here, in tension: Performance vs. Readability. Let's tackle the third problem first though, long lines: System.out.println("Good morning everyone. I am here today to present you with a very, very lengthy sentence in order to prove a point about how it looks strange amongst other code."); The best way to implement this and keep ...


37

I understand the book is written to describe C languages in general. The book is written to teach you ANSI C, not 'C languages in general' Does the book expect me to be able to translate the first program ... to a C# or C++ program? No, those are different languages, and the book does not expect you to do anything with those languages. The ...



Top 50 recent answers are included