code-reuse

ImportError: No Module Named <parent dir>

左心房为你撑大大i 提交于 2019-12-05 00:25:10
I am trying to learn programming through Python, so I apologize in advance if this is an absurdly simple question. I am attempting to simplify my convoluted directory structure and utilize some of Python's code-reuse features, I have encountered what is for me an inexplicable ImportError error. For the past several hours I've been reading about Python's import , module , and package features ( here , here , here , and here among others), yet I remain unable to solve this (seemingly) simple error. Here is the problem. I have one directory ( dir ), within which resides one sub-directory ( subdir

How do programmers practice code reuse

旧时模样 提交于 2019-12-04 18:14:30
问题 I've been a bad programmer because I am doing a copy and paste. An example is that everytime i connect to a database and retrieve a recordset, I will copy the previous code and edit, copy the code that sets the datagridview and edit. I am aware of the phrase code reuse, but I have not actually used it. How can i utilize code reuse so that I don't have to copy and paste the database code and the datagridview code., 回答1: Depending on the size of the project can change the answer. For a smaller

Is there a way to reuse data annotations?

戏子无情 提交于 2019-12-04 14:44:13
Is there a way to implement the idea of a data domains (at a property level) inside of a class that is used as a model in a view in ASP.Net MVC 4? Consider this code: public class LoginProfileModel { [DisplayName("Login ID")] [Required(ErrorMessage = "Login ID is required.")] public string LogonID { get; set; } [DisplayName("Password")] [Required(ErrorMessage = "Password cannot be blank.")] [StringLength(20, MinimumLength = 3)] [DataType(DataType.Password)] public string Password { get; set; } } Here is a LoginProfileModel in for ASP.Net MVC 4. It uses a variety of metadata/data annotations so

How do you foster the use of shared components in your organization?

那年仲夏 提交于 2019-12-04 11:53:22
If your company or project places an emphasis on (or at least appreciates) the development of code and components that can be reused and shared across projects, what are the "social engineering" things you've needed to do to facilitate the re-use the code? In my experience, code or components that are simply stated as being "reusable" won't be reused unless that code has someone to champion or evangelize it. Otherwise, people simply won't know about it. How do you make sure shared components or reusable code work in your organization? A couple of thoughts come to mind: Make them very well

What is a good strategy for separating layers for an application that can be used online and offline?

谁都会走 提交于 2019-12-04 11:31:20
I have a Java web application that has a 'disconnected' Java Swing desktop app. Using the desktop app users connect to the internet and download data they need from a server. They can disconnect and use the application offline. When they reconnect to the internet they can sync their data back to the server. The server itself is a Java EE web application and the desktop app is a limited functionality version of the web app. Up until now all business logic and data access code was coded separately for each application. The data stores were different for each application (Web is SQL Server and

Under ExtJS 4 is there a way to load external components?

百般思念 提交于 2019-12-04 11:17:17
I am trying to set up my ExtJS 4 project so I have three top level applications, for example, /foo/app.js /bar/app.js /baz/app.js Each 'top level' application is a separate ExtJS application, each with their own loaders. There are some cases were I will have general components that I want to share between all three applications, so I have /components top level directory. If I have a component name say ComponentA, /components/componenta.js How would I go about getting ComponentA into all three applications, so it could referenced or extended by the individual application? You can add this same

Is it possible to reuse partial views on multiple projects in ASP.NET MVC?

偶尔善良 提交于 2019-12-04 10:56:51
I know ASP.NET MVC 3 doesn't support area reuse, which would be very handy for, say, user admin areas of web applications, but how about partial views? Say I have Pager "control" as a Razor (or WebFormViewEngine , it doesn't matter) partial view which I can easily reuse inside my MVC application. Is it possible to reuse it in multiple MVC applications other than by creating a partial view in the new application and copy-pasting the code? Darin Dimitrov There is nothing buit-in the framework that allows you to do this. You may take a look at MVCContrib portable areas which allows you to embed

javascript BEST PRACTICE - managing scripts / code reuse

白昼怎懂夜的黑 提交于 2019-12-04 05:08:19
From reading many articles, such as How do I include a JavaScript file in another JavaScript file? - it is apparently not possible to include one script into another. So here's my question - I'm concerned about JS bloat. or having too much unused code loading with pages that don't use/need it. However, occasionally, I'll need the same functions on multiple pages, but not all pages. If we look at making logical sections of an online application into objects, such as 'customers' or 'items' - we may have a bunch of code that is specific to each of these 'objects'. As an example, I could have a

Can I share code between different parts of Chrome Extension?

旧时模样 提交于 2019-12-04 00:30:27
Let's say, I have a function: var rand = function(n) { return Math.floor(Math.random() * n); } Can I use this function in both Content Script and Background Script without copypaste? Thank you. Yes. You could have an external JS file which is loaded as part of the background and the content script (like any normal JS file). Just add it to the background and content script file arrays in the manifest and it will be loaded for you. For example if our shared function reside in sharedFunctions.js , the content script using them is in mainContentScript.js and the background code in mainBackground

How to model mixins / multiple interfaces in Haskell?

泪湿孤枕 提交于 2019-12-03 17:31:34
问题 I came across this question on modeling inheritance in Haskell and it reminded me that I have a little more complicated version of the same problem. I'll adopt the example from there because it's easier than thinking up my own. Suppose your program contains a number of types: data Camera = Camera ... data Light = SpotLight ... | DirectionalLight ... data Object = Monster ... | Player ... | NPC ... Now you want to implement some basic physics, so you want them all to have a position and a