code-reuse

Code Reusability: Is it worth it?

左心房为你撑大大i 提交于 2019-11-29 01:27:37
We all write reusable classes and code. We factor in configurability to allow us to reuse this fantastic new class again and again. We tell our bosses that spending this extra time now will save us time and money later. But in reality, for those of us who don't write third party libraries, and spend our time working on a application as a whole, how many times does that one class you spent extra time writing to be reused actually get reused in another project? How many bespoke classes do you have in your library which will get used in more than one project? My common rule of thumb is: If you

C# reusable function to dump current value of local variables

一个人想着一个人 提交于 2019-11-28 22:05:41
I would like to write a reusable function I can call within any method to log a snapshot of all the local variables. For example: void somemethod() { int a = 1; string s = "something"; dumpLocalVariables("step 1", MethodInfo.GetCurrentMethod(), this); a++; string t = s + "else"; dumpLocalVariables("step 2", MethodInfo.GetCurrentMethod(), this); } I would like to get a console output like this: step 1 Int32 a = 1 String s = something step 2 Int32 a = 2 String s = something String t = somethingelse I want to avoid providing a specific list of local variable names. The closest I could find was

Library for both iOS and OS X apps? [closed]

╄→尐↘猪︶ㄣ 提交于 2019-11-28 21:14:43
问题 For a while now I have been killing spare time by creating a 2D game programming toolkit/library. It is written in Objective C, and consists of an OpenGL rendering system and a whole bunch of AI, physics code, a bunch of specialized containers and other game related stuff. Apart from the OpenGL based View mechanism (obviously), most of this code should be easily portable to iOS since it only uses the Foundation Framework and that framework appears to be implemented on iOS. So far I have only

How can I write reusable Javascript?

白昼怎懂夜的黑 提交于 2019-11-28 16:50:44
问题 I've started to wrap my functions inside of Objects, e.g.: var Search = { carSearch: function(color) { }, peopleSearch: function(name) { }, ... } This helps a lot with readability , but I continue to have issues with reusabilty . To be more specific, the difficulty is in two areas: Receiving parameters . A lot of times I will have a search screen with multiple input fields and a button that calls the javascript search function. I have to either put a bunch of code in the onclick of the button

How do I index and make available reusable code? [closed]

倖福魔咒の 提交于 2019-11-28 10:21:56
I have many small files containing code fragments, pseudo-code algorithms, classes, templates, SQL-samples, etc., and I obviously cannot put all these into libraries. I need a practical method to index all of them, and to be able to make this index available to others. What must such an index contain to make searching easiest? Are there any such repositories available on the web? (So I can test the techniques they use.) Are there any applications already written that implement this that I can have a look at? Possible duplicate: https://stackoverflow.com/q/90300/15161 You might want to try

Does a library to prevent duplicate form submissions exist for django?

白昼怎懂夜的黑 提交于 2019-11-28 09:45:19
I am trying to find a way to prevent users from double-submitting my forms. I have javascript that disables the submit button, but there is still an occasional user who finds a way to double-submit. I have a vision of a re-usable library that I could create to protect from this. In my ideal library, the code block would look something like this: try: with acquire_lock({'field1':'abc', 'field2':'def'}) as lock: response = #do some credit card processing lock.response = response except SubmissionWasDuplicate, e: response = e.response The lock table would look something like this: duplicate

Logic code reuse between apps for Android and other platforms: To ContentProvider or not to ContentProvider?

随声附和 提交于 2019-11-28 08:15:35
问题 I'm developing an app which I want to make available both for Android and Blackberry (possibly to JavaME in the future). The business logic will be common to all the platforms - and hence, so will the corresponding layer in code. But I also have a data layer - which will obviously be different to the various platforms. My approach to this is to have a bean and an abstract DataStore class. If I were using Android's NotePad sample, it would look like this: Note Bean: public class Note { private

Add rounded corners to all UIImageViews

﹥>﹥吖頭↗ 提交于 2019-11-27 17:01:06
I would like to add some rounded corners to all of the UIImageViews in my project. I have already got the code working, but am having to apply it to every image; should I subclass UIImageView to add this? If so, can someone give me some pointers as to how to do this? Here is the code - (void)viewDidLoad { [super viewDidLoad]; NSString *mainpath = [[NSBundle mainBundle] bundlePath]; welcomeImageView.image = [UIImage imageWithContentsOfFile:[mainpath stringByAppendingString:@"/test.png"]]; welcomeImageView.layer.cornerRadius = 9.0; welcomeImageView.layer.masksToBounds = YES; welcomeImageView

How do you make code reusable?

心不动则不痛 提交于 2019-11-27 16:55:58
Any code can be reused in a way or an other, at least if you modify the code. Random code is not very reusable as such. When I read some books, they usually say that you should explicitly make the code reusable by taking into account other situations of code usage too. But certain code should not be an omnipotent all doing class either. I would like to have reusable code that I don't have to change later. How do you make code reusable? What are the requirements for code being reusable? What are the things that reusable code should definitely have and what things are optional? Galwegian See 10

Code Reusability: Is it worth it?

孤街浪徒 提交于 2019-11-27 15:59:14
问题 We all write reusable classes and code. We factor in configurability to allow us to reuse this fantastic new class again and again. We tell our bosses that spending this extra time now will save us time and money later. But in reality, for those of us who don't write third party libraries, and spend our time working on a application as a whole, how many times does that one class you spent extra time writing to be reused actually get reused in another project? How many bespoke classes do you