Search Results

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

Page 116/237 | < Previous Page | 112 113 114 115 116 117 118 119 120 121 122 123  | Next Page >

  • Using a message class static method taking in an action to wrap Try/Catch

    - by Chris Marisic
    I have a Result object that lets me pass around a List of event messages and I can check whether an action was successful or not. I've realized I've written this code in alot of places Result result; try { //Do Something ... //New result is automatically a success for not having any errors in it result = new Result(); } catch (Exception exception) { //Extension method that returns a Result from the exception result = exception.ToResult(); } if(result.Success) .... What I'm considering is replacing this usage with public static Result CatchException(Action action) { try { action(); return new Result(); } catch (Exception exception) { return exception.ToResult(); } } And then use it like var result = Result.CatchException(() => _model.Save(something)); Does anyone feel there's anything wrong with this or that I'm trading reusability for obscurity?

    Read the article

  • Is it better for class data to be passed internally or accessed directly?

    - by AaronSzy
    Example: // access fields directly private void doThis() { return doSomeWork(this.data); } // receive data as an argument private void doThis(data) { return doSomeWork(data); } The first option is coupled to the value in this.data while the second option avoids this coupling. I feel like the second option is always better. It promotes loose coupling WITHIN the class. Accessing global class data willy-nilly throughout just seems like a bad idea. Obviously this class data needs to be accessed directly at some point. However, if accesses, to this global class data can be eliminated by parameter passing, it seems that this is always preferable. The second example has the advantage of working with any data of the proper type, whereas the first is bound to working with the just class data. Even if you don't NEED the additional flexibility, it seems nice to leave it as an option. I just don't see any advantage in accessing member data directly from private methods as in the first example. Whats the best practice here? I've referenced code complete, but was not able to find anything on this particular issue.

    Read the article

  • Is there anything wrong with taking immediate actions in constructors?

    - by pestaa
    I have classes like this one: class SomeObject { public function __construct($param1, $param2) { $this->process($param1, $param2); } ... } So I can instantly "call" it as some sort of global function just like new SomeObject($arg1, $arg2); which has the benefits of staying concise, being easy to understand, but might break unwritten rules of semantics by not waiting till a method is called. Should I continue to feel bad because of a bad practice, or there's really nothing to worry about? Clarification: I do want an instance of the class. I do use internal methods of the class only. I initialize the object in the constructor, but call the "important" action-taker methods too. I am selfish in the light of these sentences.

    Read the article

  • sql: DELETE + INSERT vs UPDATE + INSERT

    - by user93422
    A similar question has been asked, but since it always depends, I'm asking for my specific situation separately. I have a web-site page that shows some data that comes from a database, and to generate the data from that database I have to do some fairly complex multiple joins queries. The data is being updated once a day (nightly). I would like to pre-generate the data for the said view to speed up the page access. For that I am creating a table that contains exact data I need. Question: for my situation, is it reasonable to do complete table wipe followed by insert? or should I do update,insert? SQL wise seems like DELETE + INSERT will be easier (it is single SQL expression). EDIT: RDBMS: MS SQL Server 2008 Ent

    Read the article

  • Application wide messaging... without singletons?

    - by StormianRootSolver
    So, I want to go for a more Singleton - less design in the future. However, there seem to be a lot of tasks in an application that can't be done in meaningful way without singletons. I call them "application wide services", but they also fall into the same category as the cross cutting concerns, which I usually fix via AOP. Lets take an example: I want an application wide message queue that dispatches messages to components, every component can subscribe and publish there, it's a very nice multicast thing. The message queue and dispatching system are usually a (rather short) singleton class, which is very easy to implement in, say, C#. You can even use double dispatching and utilize message type metadata and the like, it's all so easy to do, it's almost trivial. However, having singletons is not really "object oriented design" (it introduces global variables) and it makes testing harder. Do you have any ideas? I'm asking this question because I'm willing to learn more about this topic, a LOT more. :-)

    Read the article

  • How to have the controller change its behavior depending on the view?

    - by Ian Boyd
    If from one view a user enters some invalid data, e.g.:     E-mail: [email protected]     then i want the controller to: not place the data into the model color the text box reddish not allow the user to save But it's possible that if the user enters the same invalid data in a different view i want the controller to: place the data into the model color the text box reddish allow the user to save But it's possible that if the user enters the same invalid data in a different view i want the controller to: place the data into the model color the text box bluish allow the user to save And it's possible that another view will: place the data into the model leave the text box uncolored allow the user to save And it's possible that another view will: auto-correct the data, placing it into the model color the text-box reddish allow the user to have And it's possible for another view to: auto-correct the data, placing it into the model update the view with the new data color the text-box bluish allow the user to save [ad infinitum] Without using n-controllers for n-views, how do i do this?

    Read the article

  • Are memory leaks ever ok?

    - by Imbue
    Is it ever acceptable to have a memory leak in your C or C++ application? What if you allocate some memory and use it until the very last line of code in your application (for example, a global object's deconstructor)? As long as the memory consumption doesn't grow over time, is it OK to trust the OS to free your memory for you when your application terminates (on Windows, Mac, and Linux)? Would you even consider this a real memory leak if the memory was being used continuously until it was freed by the OS. What if a third party library forced this situation on you? Would refuse to use that third party library no matter how great it otherwise might be? I only see one practical disadvantage, and that is that these benign leaks will show up with memory leak detection tools as false positives.

    Read the article

  • Code casing question for private class fields

    - by user200295
    Take the following example public class Class1{ public string Prop1{ get {return m_Prop1;} set {m_Prop1 = value; } } private string m_Prop1; // this is standard private property variable name // how do we cap this variable name? While the compiler can figure out same casing // it makes it hard to read private Class2 Class2; // we camel case the parameter public Class1(Class2 class2){ this.Class2 = class2; } } Here are my stock rules The class name is capitalized (Class1) The public properties are capitalized (Prop1) The private field tied to a public property has m_ to indicate this. My coworker prefers _ There is some debate if using m_ or _ should be used at all, as it is like Hungarian notation. Private class fields are capitalized. The part I am trying to figure out is what do I do if when the Class name of a private field matches the private field name. For example, private Class2 Class2; This is confusing. If the private field name is not the same class, for example private string Name; , there isn't much issue. Or am I thinking about the issue wrong. Should my classes and private fields be named in such a way that they don't collide?

    Read the article

  • Unit testing directory structure

    - by zachary
    Huge project tons of classes and directories. Do I make my unit test project mirror these directories or do I put them all at the root directory? Somewhat annoying to have to make directory changes and class name changes twice.

    Read the article

  • globally get any field value in user table of logged in user

    - by Jugga
    Im making a gaming community and i wanna be able to grab any info of the user on any page without so instead of having much of queries on all pages i made this function. Is it better to do this? Will this slow down the site? /** * ??????? ???????? ?? ????? ??????? authed ?????????????. */ function UserData($f) { global $_SESSION; return mysql_result(mysql_query("SELECT `$f` FROM `users` WHERE `id` = ".intval($_SESSION['id'])), 0, $f); }

    Read the article

  • What is the correct way to open and close window/dialog?

    - by mree
    I'm trying to develop a new program. The work flow looks like this: Login --> Dashboard (Window with menus) --> Module 1 --> Module 2 --> Module 3 --> Module XXX So, to open Dashboard from Login (a Dialog), I use Dashboard *d = new Dashboard(); d->show(); close(); In Dashboard, I use these codes to reopen the Login if the user closes the Window (by clicking the 'X') closeEvent(QCloseEvent *) { Login *login = new Login(); login->show(); } With a Task Manager opened, I ran the program and monitor the memory usage. After clicking open Dashboard from Login and closing Dashboard to return to Login, I noticed that the memory keeps increasing about 500 KB. It can goes up to 20 MB from 12 MB of memory usage by just opening and closing the window/dialog. So, what did I do wrong here ? I need to know it before I continue developing those modules which will definitely eat more memory with my programming. Thanks in advance.

    Read the article

  • What do you do in your source control repository when you start a rewrite of a program?

    - by Max Schmeling
    I wrote an application a while back and have been maintaining it for a while now, but it's gotten to the point where there's several major new features to be added, a ton of changes that need made, and I know quite a few things I could do better, so I'm starting a rewrite of the entire program (using bits and pieces from original). My question is, what do you do with SVN at this point? Should I put the new version somewhere else, or should I delete the files I no longer need, add the new files, and just treat it like normal development in SVN? How have you handled this in the past?

    Read the article

  • Tool to maintain a Data Mapping between two systems

    - by ktaylorjohn
    We have XML interfaces between multiple systems. An Enterprise Domain Model is missing in the overall architecture, hence the terms Product/Customer/User means different things to different systems. We currently use excel sheets to map the elements in incoming XML to what the actual Field means within our system. Additionally, it contains the values of Mandatory/Optional and length of each field. We call this the Data Dictionary. Any changes to the XML go through rounds of deliberation and updates to Word and Excel documents. Is there a better way to do this? Any tool/GUI based approach which all systems and owners can view?

    Read the article

  • Is it bad practice to use Reflection in Unit testing?

    - by Sebi
    During the last years I always thought that in Java, Reflection is widely used during Unit testing. Since some of the variables/methods which have to be checked are private, it is somehow necessary to read the values of them. I always thought that the Reflection API is also used for this purpose. Last week i had to test some packages and therefore write some JUnit tests. As always i used Reflection to access private fields and methods. But my supervisor who checked the code wasn't really happy with that and told me that the Reflection API wasn't meant to use for such "hacking". Instead he suggested to modifiy the visibility in the production code. Is it really bad practice to use Reflection? I can't really believe that

    Read the article

  • Table in DB for generating primary keys?

    - by Sapphire
    Do you ever use a separate table for "generating" artificial primary keys for DB (and why)? What I mean is to have a table with two columns, table name and current ID - with which you could get new "ID" for some table by simply locking the row with that table name, getting the current value of the key, increment it by one, and unlock the row. Why would you prefer this over standard integer identity column? P.S. The "idea" is from Fowlers Patterns of Enterprise Application Architecture, btw...

    Read the article

  • .NET Results Class

    - by pm_2
    I have a C# function that does some processing and needs to return figures about what it has processed, success, failure, etc. Can anyone tell me if there are any standard framework classes that will handle this (for example, number of records processed, number successful, failed, etc) ? Alternatively, can anyone say how they usually handle this? Is the best way to create a class, or to use out parameters?

    Read the article

  • How to write this in better way?

    - by dario
    Hi all. Let's look at this code: IList<IHouseAnnouncement> list = new List<IHouseAnnouncement>(); var table = adapter.GetData(); //get data from repository object -> DataTable if (table.Rows.Count >= 1) { for (int i = 0; i < table.Rows.Count-1; i++) { var anno = new HouseAnnouncement(); anno.Area = float.Parse(table.Rows[i][table.powierzchniaColumn].ToString()); anno.City = table.Rows[i][table.miastoColumn].ToString(); list.Add(anno); } } return list; Is it better way to write this in less code and better fashion (must be :-) )? Maybe using labda (but let mi know how)? Thanks in advance!

    Read the article

  • Is it a problem if i query again and again to SQL Server 2005 and 2000?

    - by learner
    Window app i am constructing is for very low end machines (Celeron with max 128 RAM). From the following two approaches which one is the best (I don't want that application becomes memory hog for low end machines):- Approach One:- Query the database Select GUID from Table1 where DateTime <= @givendate which is returning me more than 300 thousands records (but only one field i.e. GUID - 300 thousands GUIDs). Now running a loop to achieve next process of this software based on GUID. Second Approach:- Query the database Select Top 1 GUID from Table1 where DateTime <= @givendate with top 1 again and again until all 300 thousands records done. It will return me only one GUID at a time, and I can do my next step of operation. What do you suggest which approach will use the less Memory Resources?? (Speed / performance is not the issue here).

    Read the article

  • Handling Multiple Form Actions on One View?

    - by Pandiya Chendur
    I have multiple master pages in my asp.net mvc web application... Each of the pages add,edit,view and delete functionalities.... What it does is i have to create multiple views for handling add,edit,view and delete functionalities (ie) the user has to navigate to another view to edit/view the details of a record... How to Handle Multiple Form Actions (ie) add,edit,view and delete functionalities on One View?

    Read the article

  • Method returns an IDisposable - Should I dispose of the result, even if it's not assigned to anythin

    - by mjd79
    This seems like a fairly straightforward question, but I couldn't find this particular use-case after some searching around. Suppose I have a simple method that, say, determines if a file is opened by some process. I can do this (not 100% correctly, but fairly well) with this: public bool IsOpen(string fileName) { try { File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.None); } catch { // if an exception is thrown, the file must be opened by some other process return true; } } (obviously this isn't the best or even correct way to determine this - File.Open throws a number of different exceptions, all with different meanings, but it works for this example) Now the File.Open call returns a FileStream, and FileStream implements IDisposable. Normally we'd want to wrap the usage of any FileStream instantiations in a using block to make sure they're disposed of properly. But what happens in the case where we don't actually assign the return value to anything? Is it still necessary to dispose of the FileStream, like so: try { using (File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.None)); { /* nop */ } } catch { return true; } Should I create a FileStream instance and dispose of that? try { using (FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.None)); } ... Or are these totally unnecessary? Can we simply call File.Open and not assign it to anything (first code example), and let the GC dispose of it right away?

    Read the article

  • Sys. engineer has decided to dynamically transform all XSLs into DLLs on website build process. DLL

    - by John Sullivan
    Hello, OS: Win XP. Here is my situation. I have a browser based application. It is "wrapped" in a Visual Basic application. Our "Systems Engineer Senior" has decided to spawn DLL files from all of our XSL pages (many of which have duplicate names) upon building a new instance of the website and have the active server pages (ASPX) use the DLL instead. This has created a "known issue" in which ~200 DLL naming conflicts occur and, thus, half of our application is broken. I think a solution to this problem is that, thankfully, we're generating the names of the DLLs and linking them up with our application dynamically. Therefore we can do something kludgy like generate a hash and append it to the end of the DLL file name when we build our website, then always reference the DLL that had some kind of random string / hash appended to its name. Aside from outright renaming the DLLs, is there another way to have multiple DLLs with the same name register for one application? I think the answer is "No, only between different applications using a special technique." Please confirm. Another question I have on my mind is whether this whole idea is a good practice -- converting our XSL pages (which we use in mass -- every time a response from our web app occurs) into DLL functions that call a "function" to do what the XSL page did via an active server page (ASPX), when we were before just sending an XML response to an XSL page via aspx.

    Read the article

  • Do I need to perform a commit after a rebase?

    - by Benjol
    I've just rebased a feature branch onto another feature branch (in preparation for rebasing everything to the head of my master), and it involved quite a few tricky merge resolutions. Is the rebase automatically saved as a commit somewhere? Just where do those modifications live? I can't see anything in gitk, or git log --oneline. (Same question for when I merge back my branch after rebasing.)

    Read the article

< Previous Page | 112 113 114 115 116 117 118 119 120 121 122 123  | Next Page >