Search Results

Search found 5915 results on 237 pages for 'practices'.

Page 94/237 | < Previous Page | 90 91 92 93 94 95 96 97 98 99 100 101  | Next Page >

  • How to save objects using Multi-Threading in Core Data?

    - by Konstantin
    I'm getting some data from the web service and saving it in the core data. This workflow looks like this: get xml feed go over every item in that feed, create a new ManagedObject for every feed item download some big binary data for every item and save it into ManagedObject call [managedObjectContext save:] Now, the problem is of course the performance - everything runs on the main thread. I'd like to re-factor as much as possible to another thread, but I'm not sure where I should start. Is it OK to put everything (1-4) to the separate thread?

    Read the article

  • C# Property Access vs Interface Implementation

    - by ehdv
    I'm writing a class to represent a Pivot Collection, the root object recognized by Pivot. A Collection has several attributes, a list of facet categories (each represented by a FacetCategory object) and a list of items (each represented by a PivotItem object). Therefore, an extremely simplified Collection reads: public class Collection { private List<FacetCategory> categories; private List<PivotItem> items; // other attributes } What I'm unsure of is how to properly grant access to those two lists. Because declaration order of both facet categories and items is visible to the user, I can't use sets, but the class also shouldn't allow duplicate categories or items. Furthermore, I'd like to make the Collection object as easy to use as possible. So my choices are: Have Collection implement IList<PivotItem> and have accessor methods for FacetCategory: In this case, one would add an item to Collection foo by writing foo.Add(bar). This works, but since a Collection is equally both kinds of list making it only pass as a list for one type (category or item) seems like a subpar solution. Create nested wrapper classes for List (CategoryList and ItemList). This has the advantage of making a consistent interface but the downside is that these properties would no longer be able to serve as lists (because I need to override the non-virtual Add method I have to implement IList rather than subclass List. Implicit casting wouldn't work because that would return the Add method to its normal behavior. Also, for reasons I can't figure out, IList is missing an AddRange method... public class Collection { private class CategoryList: IList<FacetCategory> { // ... } private readonly CategoryList categories = new CategoryList(); private readonly ItemList items = new ItemList(); public CategoryList FacetCategories { get { return categories; } set { categories.Clear(); categories.AddRange(value); } } public ItemList Items { get { return items; } set { items.Clear(); items.AddRange(value); } } } Finally, the third option is to combine options one and two, so that Collection implements IList<PivotItem> and has a property FacetCategories. Question: Which of these three is most appropriate, and why?

    Read the article

  • Should I use IDisposable for purely managed resources?

    - by John Gietzen
    Here is the scenario: I have an object called a Transaction that needs to make sure that only one entity has permission to edit it at any given time. In order to facilitate a long-lived lock, I have the class generating a token object that can be used to make the edits. You would use it like this: var transaction = new Transaction(); using (var tlock = transaction.Lock()) { transaction.Update(data, tlock); } Now, I want the TransactionLock class to implement IDisposable so that its usage can be clear. But, I don't have any unmanaged resources to dispose. however, the TransctionLock object itself is a sort of "unmanaged resource" in the sense that the CLR doesn't know how to properly finalize it. All of this would be fine and dandy, I would just use IDisposable and be done with it. However, my issue comes when I try to do this in the finalizer: ~TransactionLock() { this.Dispose(false); } I want the finalizer to release the transaction from the lock, if possible. How, in the finalizer, do I detect if the parent transaction (this.transaction) has already been finalized? Is there a better pattern I should be using? The Transaction class looks something like this: public sealed class Transaction { private readonly object lockMutex = new object(); private TransactionLock currentLock; public TransactionLock Lock() { lock (this.lockMutex) { if (this.currentLock != null) throw new InvalidOperationException(/* ... */); this.currentLock = new TransactionLock(this); return this.currentLock; } } public void Update(object data, TransactionLock tlock) { lock (this.lockMutex) { this.ValidateLock(tlock); // ... } } internal void ValidateLock(TransactionLock tlock) { if (this.currentLock == null) throw new InvalidOperationException(/* ... */); if (this.currentLock != tlock) throw new InvalidOperationException(/* ... */); } internal void Unlock(TransactionLock tlock) { lock (this.lockMutex) { this.ValidateLock(tlock); this.currentLock = null; } } }

    Read the article

  • Working with multiple input and output files in Python

    - by Morlock
    I need to open multiple files (2 input and 2 output files), do complex manipulations on the lines from input files and then append results at the end of 2 output files. I am currently using the following approach: in_1 = open(input_1) in_2 = open(input_2) out_1 = open(output_1, "w") out_2 = open(output_2, "w") # Read one line from each 'in_' file # Do many operations on the DNA sequences included in the input files # Append one line to each 'out_' file in_1.close() in_2.close() out_1.close() out_2.close() The files are huge (each potentially approaching 1Go, that is why I am reading through these input files one at a time. I am guessing that this is not a very Pythonic way to do things. :) Would using the following form good? with open("file1") as f1: with open("file2") as f2: # etc. If yes, could I do it while avoiding the highly indented code that would result? Thanks for the insights!

    Read the article

  • What is the best way to identify which form has been submitted?

    - by Rupert
    Currently, when I design my forms, I like to keep the name of the submit button equal to the id of the form. Then, in my php, I just do if(isset($_POST['submitName'])) in order to check if a form has been submitted and which form has been submitted. Firstly, are there any security problems or design flaws with this method? One problem I have encountered is when I wish to overlay my forms with javascript in order to provide faster validation to the user. For example, whilst I obviously need to retain server side validation, it is more convenient for the user if an error message is displayed inline, upon blurring an input. Additionally, it would be good to provide entire form validation, upon clicking the submit button. Therefore, when the user clicks on the form's submit button, I am stopping the default action, doing my validation, and then attempting to renable the traditional submit functionality, if the validation passes. In order to do this, I am using the form.submit() method but, unfortunately, this doesn't send the submit button variable (as it should be as form.submit() can be called without any button being clicked). This means my PHP script fails to detect that the form has been submitted. What is the correct way to work around this? It seems like the standard solution is to add a hidden field into the form, upon passing validation, which has the name of form's id. Then when form.submit() is called, this is passed along in place of the submit button. However, this solution seems very ungraceful to me and so I am wondering whether I should: a) Use an alternative method to detect which form has been submitted which doesn't rely rely on passing the submit button. If so what alternative is there? Obviously, just having an extra hidden field from the start isn't any better. b) Use an alternative Javascript solution which allows me to retain my non-Javascript design. For example, is there an alternative to form.submit() which allows me to pass in extra data? c) Suck it up and just insert a hidden field using Javascript.

    Read the article

  • Proper way of naming your Java Google App Engine Project

    - by Saif Bechan
    I am starting out with Google's App Engine in Java. I have seen the tutorial video but I do not understand the naming of the project package. It is going to be a guestbook, that's why the name is guestbook, I understand that part. But after that I see package name. 1)Is that something you import into the project, or is is something you create. I have seen this a lot in projects, something like com.xxx.xxx. 2)How do you name this type of thing or is this an import. I have looked at another tutorial there they take the naming to a whole new level. The name of both the project and the package is de.vogella.gae.java.todo. 3)What does this mean in java terms. 4)Maybe one of you can help me with this specific project I want to start. I want to create a Google App project that for now only serves static files. I will leave the project empty and just put all my static files in the war directory of the project. I want the domain name to be mydomainstatic

    Read the article

  • How do i structure my SQL Database (tables, Schemas, users, stored procedures etc.) to prepare it fo

    - by AlexRednic
    I think the title is self explanatory. What I'm looking for is material so I can further my knowledge. I've never developed a full application before so building one from scratch is a bit overwhelming for me. And the first bump in the road is the database. Websites, articles, books, elaborate answers, anything will do as long as they keep me on the right track. Thanks

    Read the article

  • How should Application.Run() be called for the main presenter a MVP WinForms app?

    - by Mr Roys
    I'm learning to apply MVP to a simple WinForms app (only one form) in C# and encountered an issue while creating the main presenter in static void Main(). Is it a good idea to expose a View from the Presenter in order to supply it as a parameter to Application.Run()? Currently, I've implemented an approach which allows me to not expose the View as a property of Presenter: static void Main() { IView view = new View(); Model model = new Model(); Presenter presenter = new Presenter(view, model); presenter.Start(); Application.Run(); } The Start and Stop methods in Presenter: public void Start() { view.Start(); } public void Stop() { view.Stop(); } The Start and Stop methods in View (a Windows Form): public void Start() { this.Show(); } public void Stop() { // only way to close a message loop called // via Application.Run(); without a Form parameter Application.Exit(); } The Application.Exit() call seems like an inelegant way to close the Form (and the application). The other alternative would be to expose the View as a public property of the Presenter in order to call Application.Run() with a Form parameter. static void Main() { IView view = new View(); Model model = new Model(); Presenter presenter = new Presenter(view, model); Application.Run(presenter.View); } The Start and Stop methods in Presenter remain the same. An additional property is added to return the View as a Form: public void Start() { view.Start(); } public void Stop() { view.Stop(); } // New property to return view as a Form for Application.Run(Form form); public System.Windows.Form View { get { return view as Form(); } } The Start and Stop methods in View (a Windows Form) would then be written as below: public void Start() { this.Show(); } public void Stop() { this.Close(); } Could anyone suggest which is the better approach and why? Or there even better ways to resolve this issue?

    Read the article

  • Should my validator have access to my entire model?

    - by wb
    As the title states I'm wondering if it's a good idea for my validation class to have access to all properties from my model. Ideally, I would like to do that because some fields require 10+ other fields to verify whether it is valid or not. I could but would rather not have functions with 10+ parameters. Or would that make the model and validator too coupled with one another? Here is a little example of what I mean. This code however does not work because it give an infinite loop! Class User Private m_UserID Private m_Validator Public Sub Class_Initialize() End Sub Public Property Let Validator(value) Set m_Validator = value m_Validator.Initialize(Me) End Property Public Property Get Validator() Validator = m_Validator End Property Public Property Let UserID(value) m_UserID = value End property Public Property Get UserID() UserID = m_Validator.IsUserIDValid() End property End Class Class Validator Private m_User Public Sub Class_Initialize() End Sub Public Sub Initialize(value) Set m_User = value End Sub Public Function IsUserIDValid() IsUserIDValid = m_User.UserID > 13 End Function End Class Dim mike : Set mike = New User mike.UserID = 123456 mike.Validator = New Validator Response.Write mike.UserID If I'm right and it is a good idea, how can I go a head and fix the infinite loop with the get property UserID? Thank you.

    Read the article

  • Java Code Formating

    - by the qwerty
    I'm using FreeMarker to generate java code, but as most of it is dynamically generated it's difficult to control the code formation. I want to get code well formatted. Does anyone knows a lib or something like a pretty printer for java code?

    Read the article

  • objectWithFieldNAme Best Practice for CoreData

    - by Rafael
    Hello, I'm trying to implements some methods for my CoreData models and I'm wonndering if the way I'm doing it is a good practice. I want to implement methods of the type getObjectsWithFieldName. This methods could be used by severals views. So the way I'm doing it is implementing a Class method in the model in the following way: +(NSArray *)getObjectWithFieldName:(NSString *)fieldName andContext:(NSManagedObjectContext *) context; Is this a good practice? Or there is another way to do it for iPhone Development? Thanks in advanced.

    Read the article

  • Is there an existing template for a new C++ Open Source project

    - by esavard
    I want to start a new C++ (Qt) Open Source project and I'm wondering if there is an existing template somewhere for files usually found in an Open Source project but that are not purely source code (README, LICENSE, CHANGELOG, etc.) I could probably find a popular Open Source project for inspiration but if there is some existing generic templates, I will use that instead. Thanks.

    Read the article

  • Giving the script tag an ID

    - by The Code Pimp
    Hi guys, i came across a scenario where giving a <script> element an "ID" would solve a problem easily. However, after reading about the script tag at w3schools and quirksmode, it seems doing so could have some unforeseen consequences. Has anyone come across any of these issues with modern browsers such as Chrome, Safari, FF3 up and IE 7 up? Thanks

    Read the article

  • What is the best practice in regards to building composite dtos off of an aggregate root with domain

    - by Chance
    I'm trying to figure out the best approach/practice for assembling a composite data transfer object off of an aggregate root and would love to hear people's thoughts on this. For example, lets say I have a root that has a few domain objects as children. I want to assemble a specific view dto, based on some business logic, that either has attributes or full dto's of it's objects. What I'm struggling with is trying to figure out where that assembly should happen. I can see it going on the domain object of the aggregate root as there is some business logic associated with it. The benefits of this approach from what I've deduced thus far is that it should reduce the inevitable business logic from bleeding outisde of the domain object. It also allows for private methods that take care of tasks that could become more complex from an external builder. The downsides being that the domain object becomes much more entrenched in the application's workflow and represents much more than just the domain object. It also could become very large in the scenario where you need multiple composite Dtos. Alternatively, I could also see it belonging to some form of transfer object assembler where there is a builder for each domain object. The domain objects would still be responsible for GetDto() and UpdateFromDto(dto). Outside of that, the builder would handle the construction and deconstruction of composite dtos. The downside is kind of mentioned above, where I fear this will easily lead to developers unfamiliar with DDD bleeding a ton of business logic into the assembler which is what I want to desperately avoid. Any thoughts would be greatly apperciated.

    Read the article

  • Is str.replace(..).replace(..) ad nauseam a standard idiom in Python?

    - by meeselet
    For instance, say I wanted a function to escape a string for use in HTML (as in Django's escape filter): def escape(string): """ Returns the given string with ampersands, quotes and angle brackets encoded. """ return string.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace("'", '&#39;').replace('"', '&quot;') This works, but it gets ugly quickly and appears to have poor algorithmic performance (in this example, the string is repeatedly traversed 5 times). What would be better is something like this: def escape(string): """ Returns the given string with ampersands, quotes and angle brackets encoded. """ # Note that ampersands must be escaped first; the rest can be escaped in # any order. return replace_multi(string.replace('&', '&amp;'), {'<': '&lt;', '>': '&gt;', "'": '&#39;', '"': '&quot;'}) Does such a function exist, or is the standard Python idiom to use what I wrote before?

    Read the article

  • Eclipse: Should I create a workspace for each project ?

    - by Zombies
    I am simply wondering whether it is best to put all of my Eclipse projects into one workspace, or do a 1 workspace per 1 project. I am just a solo developer, for hobby more or less, but the apps I create do actually have production versions that are running on rather frequent cron jobs, so its almost like an amateur production environment. The only problems I have noticed so far is for exporting JARs, I have the potential to include source files from other projects which seems like it could get messy (maybe?).

    Read the article

  • DRYing up Rails Views with Nested Resources

    - by viatropos
    What is your solution to the problem if you have a model that is both not-nested and nested, such as products: a "Product" can belong_to say an "Event", and a Product can also just be independent. This means I can have routes like this: map.resources :products # /products map.resources :events do |event| event.resources :products # /events/1/products end How do you handle that in your views properly? Note: this is for an admin panel. I want to be able to have a "Create Event" page, with a side panel for creating tickets (Product), forms, and checking who's rsvp'd. So you'd click on the "Event Tickets" side panel button, and it'd take you to /events/my-new-event/tickets. But there's also a root "Products" tab for the admin panel, which could list tickets and other random products. The 'tickets' and 'products' views look 90% the same, but the tickets will have some info about the event it belongs to. It seems like I'd have to have views like this: products/index.haml products/show.haml events/products/index.haml events/products/show.haml But that doesn't seem DRY. Or I could have conditionals checking to see if the product had an Event (@product.event.nil?), but then the views would be hard to understand. How do you deal with these situations? Thanks so much.

    Read the article

  • distributing R package with optional S4 syntax sugar

    - by mariotomo
    I've written a small package for logging, I'm distributing it through r-forge, recently I received some very interesting feedback on how to make it easier to use, but this functionality is based on stuff (setRefClass) that was added to R in 2.12. I'd like to keep distributing the package also for R-2.9, so I'm looking for a way to include or exclude the S4 syntactical sugar automatically, and include it when the library is loaded on a R = 2.12 system. one other option I see, that is to write a small S4 package that needs 2.12, imports the simpler logging package and exports the syntactically sugared interface... I don't like it too much, as I'd need to choose a different name for the S4 package.

    Read the article

  • Writing a custom iterator -- what to do if you're at the end of the array?

    - by Goose Bumper
    I'm writing a custom iterator for a Matrix class, and I want to implement the increment method, which gets called when the iterator is incremented: void MatrixIterator::increment() { // go to the next element } Suppose the iterator has been incremented too many times and now points to past the end of the matrix (i.e. past the one-past-the-end point). What is the best practice for this situation? Should I catch this with an assert, or should I just say it's the user's responsibility to keep track of where the iterator is pointing and it's none of my business?

    Read the article

  • How to allow for modular development while still running in same JVM?

    - by Marcus
    Our current app runs in a single JVM. We are now splitting up the app into separate logical services where each service runs in its own JVM. The split is being done to allow a single service to be modified and deployed without impacting the entire system. This reduces the need to QA the entire system - just need to QA the interaction with the service being changed. For interservice communication we use a combination of REST, an MQ system bus, and database views. What I don't like about this: REST means we have to marshal data to/from XML DB views couple the systems together which defeats the whole concept of separate services MQ / system bus is added complexity There is inevitably some code duplication between services You have set up n JBoss server configurations, we have to do n number of deployments, n number of set up scripts, etc, etc. Is there a better way to structure an internal application to allow modular development and deployment while allowing the app to run in a single JVM (and achieving the associated benefits)?

    Read the article

  • Advice on a simple Windows Form

    - by Austin Hyde
    I have a VERY simple windows form that the user uses to manage "Stores". Each store has a name and number, and is kept in a corresponding DB table. The form has a listbox of stores, an add button that creates a new store, a delete button, and an edit button. Beside those I have text boxes for the name and number, and save/cancel buttons. When the user chooses a store from the list box, and clicks 'edit', the textboxes become populated and save/cancel become active. When the user clicks 'add', I create a new Store, add it to the listbox, activate the textboxes and save/cancel buttons, then commit it to the database when the user clicks 'save', or discards it when the user clicks 'cancel'. Right now, my event system looks like this (in psuedo-code. It's just shorter that way.) add->click: store = new Store() listbox.add(store) populateAndEdit(store) delete->click: store = listbox.selectedItem db.deleteOnSubmit(store) listbox.remove(store) db.submit() edit->click: populateAndEdit(listbox.selectedItem) save->click: parseAndSave(listbox.selectedItem) db.submit() disableTexts() cancel->click: disableTexts() The problem is in how I determine if we are inserting a new Store, or updating an existing one. The obvious solution to me would be to make it a "modal" process - that is, when I click edit, I go into edit mode, and the save button does things differently than if I were in add mode. I know I could make this more MVC-like, but I don't really think this simple form merits the added complexity. I'm not very experienced with winforms, so I'm not sure if I even have the right idea for how to tackle this. Is there a better way to do this? I would like to keep it simple, but usable.

    Read the article

  • .Net Compact Framework Tips, Tricks, and Gotchas

    - by Mat Nadrofsky
    Hey everyone, We work extensively in the .Net Compact Framework and Windows Mobile. I've seen plenty of questions come up regarding specifics to development of ASP.Net apps or other .Net based desktop apps but nothing CF specific. Anyone else a mobile developer out there that can share some things to start doing, stop doing, and avoid doing when developing in the Compact Framework?

    Read the article

  • Style of if: to nest or not to nest

    - by Marco
    A colleague of mine and me had a discussion about the following best-practice issue. Most functions/methods start with some parameter checking. I advocate the following style, which avoids nesting. if (parameter one is ugly) return ERROR; if (parameter two is nonsense || it is raining) return ERROR; // do the useful stuff return result; He, who comes from a more functional/logic programming background, prefers the following, because it reduces the number of exit points from the function. if (parameter one is ok) { if (parameter two is ok && the sun is shining) { // do the useful stuff return result } } return ERROR; Which one would you prefer and why?

    Read the article

< Previous Page | 90 91 92 93 94 95 96 97 98 99 100 101  | Next Page >