Search Results

Search found 12660 results on 507 pages for 'programming pearls'.

Page 126/507 | < Previous Page | 122 123 124 125 126 127 128 129 130 131 132 133  | Next Page >

  • Programming logic best practice - redundant checks

    - by eldblz
    I'm creating a large PHP project and I've a trivial doubt about how to proceed. Assume we got a class books, in this class I've the method ReturnInfo: function ReturnInfo($id) { if( is_numeric($id) ) { $query = "SELECT * FROM books WHERE id='" . $id . "' LIMIT 1;"; if( $row = $this->DBDrive->ExecuteQuery($query, $FetchResults=TRUE) ) { return $row; } else { return FALSE; } } else { throw new Exception('Books - ReturnInfo - id not valid.'); } } Then i have another method PrintInfo function PrintInfo($id) { print_r( $this->ReturnInfo($id) ); } Obviously the code sample are just for example and not actual production code. In the second method should I check (again) if id is numeric ? Or can I skip it because is already taken care in the first method and if it's not an exception will be thrown? Till now I always wrote code with redundant checks (no matter if already checked elsewhere i'll check it also here) Is there a best practice? Is just common sense? Thank you in advance for your kind replies.

    Read the article

  • what does it mean to make a process automatic (through programming)

    - by incrediman
    For example, if I currently have to resize image on my own with photoshop, but am developing a c++ app to do it for me, what am I doing to the process? I realize that the process will be automated. What I'm looking for is this (fill in the blank): It will be much faster after I've _ _ _ _ _ _d the process which is currently manual but which will be automatic after I'm done with it. I tried autonomize, but it isn't a word :(

    Read the article

  • Socket Programming for the Web

    - by Benny
    I have to interact with a legacy system that accepts socket communication and messages. My goal is to make the application cross-platform, but I need the ability to push messages to the client (i.e. - .NET's WCF, Java's Comet) and detect when the user closes out of their browser to destroy the socket. I have built a prototype of .NET wrapper + WCF + Silverlight but it is so disconnected it is difficult to manage the state of the user and seems to be a nightmare to support. All of that considered, what would be my best option?

    Read the article

  • Issue Displaying/Hiding Views (Obj-C iPhone Programming)

    - by roswell
    All right all, So I've got a UITableView that is inited in applicationDidFinishLaunching like so: [self showForumList]; Said method does this: -(void)showForumList { ForumList *fl = [ForumList alloc]; [fl initWithNibName:@"ForumList" bundle:[NSBundle mainBundle]]; self.ForumList = fl; [window addSubview:[self.ForumList view]]; [fl release]; }where self.ForumList is previously defined in the interface as ForumList *ForumList;, etc. Now, in ForumList (itself an extension of UITableViewController obviously), I've got didSelectRowAtIndexPath: -- within it I have the following code: Forum *f = [Forum alloc]; NSArray *forums = [f getForumList]; NSDictionary *selectedForum = [forums objectAtIndex:[indexPath row]]; NSString *Url = [selectedForum objectForKey:@"url"]; NSString *Username = [selectedForum objectForKey:@"username"]; NSString *Password = [selectedForum objectForKey:@"password"]; NSLog(@"Identified press on forum %@ (%@/%@)", Url, Username, Password); [self.globalDelegate showForumListFromForumUsingUrl:Url username:Username password:Password]; [self.globalDelegate closeForumList]; NSLog(@"ForumListFromForum init"); Both of the NSLog calls in this function are executed and perform as they should. Now, here is where the issue starts. self.globalDelegate is defined as AppDelegate *globalDelegate; in the Interface specification in my header file. However, [self.globalDelegate showForumListFromForumUsingUrl:username:password] and and [self.globalDelegate closeForumList] are never actually called. They look like so: -(void)closeForumList { NSLog(@"Hiding forum list"); [[self.ForumList view] removeFromSuperview]; } -(void)showForumListFromForumUsingUrl:(NSString *)Url username:(NSString *)Username password:(NSString *)Password { NSLog(@"Showing forum list from forum"); ForumListFromForum *fl = [ForumListFromForum alloc]; [fl initWithNibName:@"ForumListFromForum" bundle:[NSBundle mainBundle]]; [fl initFromForumWithUrl:Url username:Username password:Password]; self.ForumListFromForum = fl; [window addSubview:[self.ForumListFromForum view]]; [fl release]; } The app does not respond to my press and neither of these NSLog calls are made. Any idea where I've gone wrong?

    Read the article

  • Simple Thread Programming

    - by mike
    I have started to play with threads in c#, but need now help, here is my code: public partial class Form1 : Form { public Form1() { InitializeComponent(); DoCount(); } public void DoCount() { for (int i = 0; i < 100; i++) { objTextBox.Text = i.ToString(); Thread.Sleep(100); } } } its a simple win forms with a textbox, i want to see the "counting", but as you see in my code, the textbox shows me 99, it count till 99 and then shows up.. i`ll think, i have to manage this in a new thread but dont know how!

    Read the article

  • programming in lua, objects

    - by anon
    Sample code: function Account:new (o) o = o or {} -- create object if user does not provide one setmetatable(o, self) self.__index = self return o end taken from: http://www.lua.org/pil/16.1.html What is the purpose of the: self.__index = self line? And why is it executed every time an object is created?

    Read the article

  • Javascript function programming — receiving elaborate parameters

    - by Barney
    I'm writing a Javascript function that would manipulate an array written on-the-fly and sent as a parameter. The function is written as follows: function returnJourney(animation,clean){ var properties = {}; // loads of other inane stuff for(i in animation[0]) properties[animation[0][i]] = animation[0].i; // heaps more inane stuff } The animation in question is a set of parameters for a jQuery animation. Typically it takes the format of ({key:value,key:value},speedAsInteger,modifierAsString). So to kick off initial debugging I call it with: returnJouney(({'foo':'bar'},3000),1); And straight off the bat things are way off. As far as I see it this would have returnJourney acknowledge clean === 1, and animation being an array with an object as its first child and the number 3000 as its second. Firebug tells me animation evaluates as the number 3000. What am I doing wrong?

    Read the article

  • The D Programming Language for Game Development

    - by n2liquid
    Hi all, Recently I've been bothered because I reached a point in which C++ (even 0x) felt very limited, so I started looking for alternatives. Forget Java, C#, Python or Ruby. I still like the low-level nature of C++ and I'm not fond of virtual machines. Further, I'm a game engine developer, so I have to develop core routines which must be really fast, and lately I've been hungry for code expressiveness. C++ is an almost-there language for me, but there are many exceptions on how to use templates, and GCC isn't optimizing stuff as well as I'd hoped it would. So I'm considering to start learning D. Do you think it will suffice my needs as a game developer? I'm weary because I've never heard of D being used for that. Thanks!

    Read the article

  • Socket Programming : Inputstream Stuck in loop - read() always return 0

    - by Atom Skaa ska Hic
    Server side code public static boolean sendFile() { int start = Integer.parseInt(startAndEnd[0]) - 1; int end = Integer.parseInt(startAndEnd[1]) - 1; int size = (end - start) + 1; try { bos = new BufferedOutputStream(initSocket.getOutputStream()); bos.write(byteArr,start,size); bos.flush(); bos.close(); initSocket.close(); System.out.println("Send file to : " + initSocket); } catch (IOException e) { System.out.println(e.getLocalizedMessage()); disconnected(); return false; } return true; } Client Side public boolean receiveFile() { int current = 0; try { int bytesRead = bis.read(byteArr,0,byteArr.length); System.out.println("Receive file from : " + client); current = bytesRead; do { bytesRead = bis.read(byteArr, current, (byteArr.length-current)); if(bytesRead >= 0) current += bytesRead; } while(bytesRead != -1); bis.close(); bos.write(byteArr, 0 , current); bos.flush(); bos.close(); } catch (IOException e) { System.out.println(e.getLocalizedMessage()); disconnected(); return false; } return true; } Client side is multithreading,server side not use multithreading. I just paste some code that made problem if you want see all code please tell me. After I debug the code, I found that if I set max thread to any and then the first thread always stuck in this loop. That bis.read(....) always return 0. Although, server had close stream and it not get out of the loop. I don't know why ... But another threads are work correctly. do { bytesRead = bis.read(byteArr, current, (byteArr.length-current)); if(bytesRead >= 0) current += bytesRead; } while(bytesRead != -1);

    Read the article

  • Small utilities useful while programming [closed]

    - by subSeven
    What small and cool applications that can be helpful for programmer do you know ? I think about programs that not very famous. I know three: http://advsys.net/ken/download.htm EvalDraw - for protoyping games http://www.drpetter.se/project_sfxr.html sfxr - for makeing sound http://www.kloonigames.com/blog/general/timelog timelog - for mangament time of project

    Read the article

  • "for" loop from program 7.6 from Kochan's "Programming in Objective-C"

    - by Mr_Vlasov
    "The sigma notation is shorthand for a summation. Its use here means to add the values of 1/2^i, where i varies from 1 to n. That is, add 1/2 + 1/4 + 1/8 .... If you make the value of n large enough, the sum of this series should approach 1. Let’s experiment with different values for n to see how close we get." #import "Fraction.h" int main (int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; Fraction *aFraction = [[Fraction alloc] init]; Fraction *sum = [[Fraction alloc] init], *sum2; int i, n, pow2; [sum setTo: 0 over: 1]; // set 1st fraction to 0 NSLog (@"Enter your value for n:"); scanf ("%i", &n); pow2 = 2; for (i = 1; i <= n; ++i) { [aFraction setTo: 1 over: pow2]; sum2 = [sum add: aFraction]; [sum release]; // release previous sum sum = sum2; pow2 *= 2; } NSLog (@"After %i iterations, the sum is %g", n, [sum convertToNum]); [aFraction release]; [sum release]; [pool drain]; return 0; } Question: Why do we have to create additional variable sum2 that we are using in the "for" loop? Why do we need "release previous sum" here and then again give it a value that we just released? : sum2 = [sum add: aFraction]; [sum release]; // release previous sum sum = sum2; Is it just for the sake of avoiding memory leakage? (method "add" initializes a variable that is stored in sum2)

    Read the article

  • iPhone Application and programming Updates

    - by Cheryl
    Hi When a user logs into my iPhone App. I store their userID and relevant information in [NSUserDefaults standardUserDefaults]. This way they are not required to log in each time they access my application. When my application is live in the app store and I make updates to the code will this information be lost - will they then be required to log in? If so how do I go about preserving this information when I make updates? And while I can't image this happening but should a user choose to delete my application after they have installed it - how would I know that they have deleted it? I am using the push notifications and would like to flag the user as not being active so that I don't keep pushing out notifications to them. Thanks Very Much Cheryl

    Read the article

  • Your favorite time-off between programming.

    - by Harsha
    I am sure all coding pundits here will have one (or multiple) ways of spending some time-off between hectic coding sessions just to relax. Would love to hear from you all as I am a newbie and want to take little breaks (non-physical) from coding and do things which actually help me focus again. Thanks.

    Read the article

  • Need help in sorting the programming buzz-words

    - by cwap
    How do you sort out the good buzz from the bad buzz? - I really need your help here :) I see a lot of buzz-words nowadays, both here on SO and in school. For example, we had a teacher who everyone respected, who said "be careful about gold-plating and death-by-interfacing". Now, everyone and their mama cries whenever I'm creating an interface.. Another example would be here on SO where lately "premature optimization is the root of all evil", so everytime someone asks a perfomance question, he'll get that sentence thrown in his face. A few months ago I remember it was all about NHibernate in here, etc., etc... These things comes and goes, but only the good buzz stays. Now, how do you seperate the good from the bad? By reading blogs from respected persons? By trying to come to a conclusion on your own, and then try to convince others that you're right? By simply ignoring it?

    Read the article

  • Programming DataEntry&Forms: Population of Official Common Data Lists

    - by rlb.usa
    As a programmer of data-entry forms of all kinds, I often find myself making fields for things like Country and State. Consider: Perhaps a list the 50 United States names is an easy thing to find (does one include DC?) , but the countries are not. Nearly every site you find has a differing list with all of the political goings on over the years, and they become outdated quickly. What's the best practice regarding population of these kinds of lists? Is there an official list somewhere that one uses to populate these kinds of formal/official fields? Where do you get this data from, when it's not exactly specified in the specs?

    Read the article

  • telephone application programming on Linux

    - by Daniel Stevens
    I'm a Linux user looking to write a program which will pick up the phone, dial a number, play a recording and record what the person on the other end of the line says and save it to an audio file. I will want to use the modem that came with my computer if possible. What should I use to write this program?

    Read the article

  • Dealbreakers for new programming jobs?

    - by Echostorm
    What might be said or implied at an interview or job posting that should set off alarm bells for a coder? I'm still only a few years in the industry but I already know to look out for excessive red tape and bureaucracy. Cubes and a noisy office also tell me that I'll be both miserable and unproductive and that management does not appreciate what coders need to work well. Edit: The way things are going I'm taking extra time to look at the company's stability. If they depend on a single vendor for their livelihood and could be out of business if the vendor decides they don't really need the service or can do it in-house. What are your dealbreakers?

    Read the article

  • OpenSource programming-languages in development?

    - by pile of junk
    I'm very interested in interpreter and compiler development and because I don't want to continue building mini compilers and interpreters I thought I could help some open-source project. Are there currently open-source projects on compilers/interpreters in early stages seeking developers? I mean yeah.. There won't be much to do for someone like me in Python, Ruby, and so on.

    Read the article

  • Programming to interfaces while mapping with Fluent NHibernate.

    - by Lucious
    Fluent Mapping I Have the following scenario public class CustomerMap : ClassMap { public CustomerMap() { Table("Customer"); Id(c = c.Id); Map(c = c.Name); HasMany(c = c.Orders); } } public class OrderMap : ClassMap<IOrder> { public OrderMap() { Table("Orders"); References(o => o.Customer).Access.; Id(o => o.Id); Map(o => o.DateCreated); } } Problems When schema exported the order table has two columns ICustomer_Id,Customer_Id. refers to an unmapped class Order exception Can you please help me out?

    Read the article

< Previous Page | 122 123 124 125 126 127 128 129 130 131 132 133  | Next Page >