code-organization

Are unnecessary include files an overhead?

醉酒当歌 提交于 2019-12-06 16:44:37
问题 I have seen a couple of questions on how to detect unnecessary #include files in a C++ project. This question has often intrigued me, but I have never found a satisfactory answer. If there are some header files included which, are not being used in a c++ project, is that an overhead? I understand that it means that before compilation the contents of all the header files would be copied into the included source files and that would result in a lot of unnecessary compilation. How far does this

How to use encoder factory in Symfony 2 inside the model setter?

心已入冬 提交于 2019-12-06 02:21:50
问题 This question about Symfony 2.1 How can I encode User password with: $factory = $this->get('security.encoder_factory'); $user = new Acme\UserBundle\Entity\User(); $encoder = $factory->getEncoder($user); $password = $encoder->encodePassword('ryanpass', $user->getSalt()); $user->setPassword($password); And base config: # app/config/security.yml security: # ... encoders: Acme\UserBundle\Entity\User: sha512 Inside the setter models: class User implements UserInterface, \Serializable { public

How to organize Data Access Layer (DAL) in ASP.NET

只谈情不闲聊 提交于 2019-12-05 12:25:31
I have an ASP.NET Web Forms application developed in C#. I would like to give structure my application by separating the DAL tasks from the code behind. I created a class in App_Code, DBUtilities that takes care of the communication with the database, in order not to have duplicated code all along the application. The class has methods to get datatables, scalar values, etc... and they accept as parameters the connection string name and the query command as string. The problem is that I have still all the queries' commands in my code behind. Many of them are duplicated all around the pages and

Implementing interfaces in partial classes

好久不见. 提交于 2019-12-05 02:26:25
Consider a class which implements a lot of interfaces, would it make sense to implement each interface in a separate file using partial class definitions? Would this be an abuse of the language feature or is it an idiom I'm unaware of? If your class has to implement many interfaces, that's a reasonable way of managing the source, yes. You can edit the project file to make several of them depend on one "main" class file, which makes the Solution Explorer easier to work with. You should ask yourself whether you shouldn't have several smaller classes each implementing a single interface though.

Is it safe to indent with 2 spaces?

廉价感情. 提交于 2019-12-05 01:40:36
I know the general answer to "How should I indent my code" is generally "do as you wish but do it the same way as everyone on your team", but in the last time I've seen many projects and platforms relying on a 2-space indentation . I just want to make sure I get the "best bang for my buck" when indenting and make sure it's future-proof. Changing the structure in a project later on is a pretty big problem considering compatibility, etc. Most projects now rely on 2 Spaces , 4 Spaces or Tabs . Projects and their indentation: tabs WordPress jQuery CakePHP Git Linux Kernel (doesn't seem to be

Adding Existing Files To Different Visual Studio 2010 Project

心不动则不痛 提交于 2019-12-04 16:34:41
问题 It is possible to add files to a visual studio project that is located in a different directory however keep the files in those directories and update those file when you update the file in the project? When I add existing files to a project, all it does is copy them to the project and then update the copied files, not the original files. Is there any way to get it to work the other way? 回答1: You should add them as a link/shortcut Right-click the project, select Add > Existing Item, and in

C++ project source code layout

别说谁变了你拦得住时间么 提交于 2019-12-04 03:51:09
One of the popular way to organize project directory is more or less like this: MyLib +--mylib_class_a.h mylib_class_a.cpp mylib_library_private_helpers.h mylib_library_private_helpers.cpp MyApp +--other_class.h other_class.cpp app.cpp app.cpp : #include "other_class.h" #include <mylib_class_a.h> // using library MyLib All .h and .cpp files for the same library are in the same directory. To avoid name collision, file names are often prefix with company name and/or library name. MyLib will be in MyApp's header search path, etc. I'm not a fan of prefixing filenames, but I like the idea of

Avoiding repeat of code after loop?

痴心易碎 提交于 2019-12-03 23:32:19
I often end up writing a bit of code twice when using a loops. For example, while going over the Udacity computer science course, I wrote the code (for a function to find the most sequentially repeated element): def longest_repetition(l): if not l: return None most_reps = count = 0 longest = prv = None for i in l: if i == prv: count += 1 else: if count > most_reps: longest = prv most_reps = count count = 1 prv = i if count > most_reps: longest = prv return longest In this case, I'm checking twice if the count is greater than the previously most repeated element. This happens both when the

Best way to organize MATLAB classes? [closed]

两盒软妹~` 提交于 2019-12-03 19:11:33
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . MATLAB has two ways of organizing classes: @-directories: @ClassName\ ClassName.m Method1.m Method2.m Single files: ClassName.m: classdef ClassName methods % all methods included here end end The first style existed before the new classdef syntax, but seems to be a more

Are type fields pure evil?

雨燕双飞 提交于 2019-12-03 13:56:39
问题 As discusses in The c++ Programming Language 3rd Edition in section 12.2.5, type fields tend to create code that is less versatile, error-prone, less intuitive, and less maintainable than the equivalent code that uses virtual functions and polymorphism. As a short example, here is how a type field would be used: void print(const Shape &s) { switch(s.type) { case Shape::TRIANGE: cout << "Triangle" << endl; case Shape::SQUARE: cout << "Square" << endl; default: cout << "None" << endl; } }