Questions tagged [program-flow]

69 questions
37
votes
8 answers

PHP "or" Syntax

I've seen this a lot: $fp = fopen($filepath, "w") or die(); But I can't seem to find any real documentation on this "or" syntax. It's obvious enough what it does, but can I use it anywhere? And must it be followed by die()? Are there any caveats to…
Andrew
  • 2,838
  • 2
  • 28
  • 35
31
votes
12 answers

Programming style: should you return early if a guard condition is not satisfied?

One thing I've sometimes wondered is which is the better style out of the two shown below (if any)? Is it better to return immediately if a guard condition hasn't been satisfied, or should you only do the other stuff if the guard condition is…
John Topley
  • 107,187
  • 45
  • 188
  • 235
18
votes
3 answers

Accessing the containing class of an inner class in Java

This is what I'm doing now. Is there a better way to access the super class? public class SearchWidget { private void addWishlistButton() { final SearchWidget thisWidget = this; button.addClickHandler(new ClickHandler() { …
gerdemb
  • 10,547
  • 15
  • 62
  • 71
11
votes
1 answer

Does javascript event handling occur inside or outside the program flow?

This question is related to Javascript event handling and flow control, but it is one step beyond. The question that remains unanswered is: when an event is fired and control is returned to the browser, could the browser decide to handle other…
Carlo Roosen
  • 945
  • 8
  • 15
6
votes
3 answers

How is GUI and Game Program Flow compared to Web programs

I've been developing Web applications for a while now and have dipped my toe into GUI and Game application development. In the web application (php for me), a request is made to the file, that file includes all the necessary files to process the…
Ólafur Waage
  • 64,767
  • 17
  • 135
  • 193
5
votes
2 answers

Should one use `if ($a != NULL)` or `if ($a !== NULL)` to control program flow?

This is perhaps a painfully basic question to answer, but I'm wondering about performance issues regarding using PHP's if identical !== versus if equal != to control flow. Consider the following trivial PHP function:
msanford
  • 10,127
  • 8
  • 56
  • 83
5
votes
2 answers

Do we need to create a error handler for each subroutine?

I copy a piece of code from SO as an example. The subroutine contains an error handler. Should one make an error handler for all Subs? Public Sub SubA() On Error Goto ProcError Connection.Open Open File for Writing …
lamwaiman1988
  • 3,497
  • 15
  • 50
  • 87
4
votes
2 answers

Would this be an example of short circuiting?

If I ask a user to input an int, and need to check if it is within the range of indices of an array before checking the array at that index to see if it's not null, would that be an example of "short circuiting"? Because if the array size is only 5…
user3059511
3
votes
5 answers

Proper disposal of filestreams and binary streams and disposing of filestreams

As it is, I tried error-proofing my code and ended up making it look quite messy. I have a function set up to read a certain type of file. I want the function to return false if there was a problem, or true if everything worked. I'm having trouble…
mowwwalker
  • 14,309
  • 23
  • 87
  • 144
3
votes
2 answers

Current possibilities for tracing program flow in C#?

I have used Postsharp a few years ago to trace program flow during execution without needing to manually add trace statements to the methods. Is there any other new ways to trace execution to to debug output in a similar way? (Preferably a way that…
Carl R
  • 7,760
  • 4
  • 41
  • 76
3
votes
4 answers

Weird bug in Java try-catch-finally

I'm using JODConverter to convert .xls and .ppt to .pdf format. For this i have code something like try{ //do something System.out.println("connecting to open office"); OpenOfficeConnection connection = new…
r15habh
  • 1,398
  • 2
  • 18
  • 31
3
votes
5 answers

Program flow after an exception is thrown in C#

Hi I'm looking at some old c# code and noticing a lot of code like this: void SomeFunction() { if (key.Length != Dimensions) { throw new KeySizeException(); } else { SomeOtherFunction(); } } I want to know if…
CodeAndCats
  • 6,372
  • 7
  • 38
  • 57
3
votes
3 answers

Java Profilers That Display Per Request Statistics and Program Flow

I'm looking for profilers that support per request profiling statistics, ideally along the programs flow (not the usual thread call stack). So basically a profiler call stack + sequential calls view for each single request, something like…
Elmar Weber
  • 2,393
  • 24
  • 24
3
votes
4 answers

try-catch-finally block in java

As per my understanding, I want to follow the best practice for releasing the resources at the end to prevent any connection leaks. Here is my code in HelperClass. public static DynamoDB getDynamoDBConnection() { try { dynamoDB =…
Chandz
  • 975
  • 3
  • 13
  • 28
3
votes
1 answer

How to break out of begin block in Ruby?

How can I break out of the begin block and jump to the rescue block? def function begin @document = Document.find_by(:token => params[:id]) next if @document.sent_at < 3.days.ago # how can I skip to the rescue block here? …
Tintin81
  • 8,860
  • 17
  • 66
  • 143
1
2 3 4 5