|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On March 29 2013 02:27 darkness wrote:By code convention, the correct try-catch should look like: try { statements; } catch (ExceptionClass e) { statements }
However, I think this is more readable: try { statements; } catch (ExceptionClass e) { statements }
Sure, they may want to emphasise that catch is "part of" try{}, but it looks better if it's on a new line imho. Comments? Source: http://www.oracle.com/technetwork/java/codeconventions-150003.pdf ( 7.9)
I like your style more than the first one. I even prefer:
try { statements; } catch (ExceptionClass e) { statements }
I think that is even more readable.
|
On March 29 2013 03:10 POiNTx wrote:Show nested quote +On March 29 2013 02:27 darkness wrote:By code convention, the correct try-catch should look like: try { statements; } catch (ExceptionClass e) { statements }
However, I think this is more readable: try { statements; } catch (ExceptionClass e) { statements }
Sure, they may want to emphasise that catch is "part of" try{}, but it looks better if it's on a new line imho. Comments? Source: http://www.oracle.com/technetwork/java/codeconventions-150003.pdf ( 7.9) I like your style more than the first one. I even prefer: try { statements; } catch (ExceptionClass e) { statements }
I think that is even more readable. This is another well-established coding convention, and what is standard in C# (see Microsoft's guidelines here: http://msdn.microsoft.com/en-us/library/vstudio/ff926074.aspx). But what darkness proposed was a really weird and ugly hybrid form of the Java standard and the C# one :D As someone said, as long as everybody who works on the same code uses the same conventions that's fine, but it's better to pick up established conventions as your own to begin with.
I personally follow the Oracle Java Code conventions to code in Java and the Microsoft guidelines to code in C#. I believe it's good to be able to follow flexibly whatever convention you have to use in a given situation.
Edit: Damn and it's been such a long time since I've written some C#. I need me some C#  It's so much more cool, fun and powerful than Java... :'(
|
Wars have been fought over brace styles. To each their own, the most important part is that a code base uses a consistent style.
Having said that, there is only One True Brace Style.
|
Personally, I do this a lot.
try { statements; } catch (ExceptionClass e) { //TODO add catch statements never }
|
On March 29 2013 06:01 obesechicken13 wrote:Personally, I do this a lot. try { statements; } catch (ExceptionClass e) { //TODO add catch statements never }
LOL. As do we all, my friend.
|
try { ugly method call throwing checked exception }catch( Exception e ){ rethrow(e); }
Where rethrow(Exception e) is an ugly nice hack exploiting type erasure to be able to throw checked exception without actually declaring them in a throws exception.
Much much better than swallowing it, which is plain disgusting, or rethrowing it as RuntimeException, which you can't catch properly at higher levels.
|
On March 29 2013 06:47 Frigo wrote:try { ugly method call throwing checked exception }catch( Exception e ){ rethrow(e); }Where rethrow(Exception e) is a n ugly nice hack exploiting type erasure to be able to throw checked exception without actually declaring them in a throws exception. Much much better than swallowing it, which is plain disgusting, or rethrowing it as RuntimeException, which you can't catch properly at higher levels.
Exception structures may be ugly/hackish and difficult to use effectively, but I just think of the alternatives and shudder.
HealthMonitors and run-time error checking are kind of a bust. I often just let my kernel panic and core dump than have to deal with a health monitor. Easier to debug (lol).
|
On March 29 2013 07:00 RoyGBiv_13 wrote:Show nested quote +On March 29 2013 06:47 Frigo wrote:try { ugly method call throwing checked exception }catch( Exception e ){ rethrow(e); }Where rethrow(Exception e) is a n ugly nice hack exploiting type erasure to be able to throw checked exception without actually declaring them in a throws exception. Much much better than swallowing it, which is plain disgusting, or rethrowing it as RuntimeException, which you can't catch properly at higher levels. Exception structures may be ugly/hackish and difficult to use effectively, but I just think of the alternatives and shudder. HealthMonitors and run-time error checking are kind of a bust. I often just let my kernel panic and core dump than have to deal with a health monitor. Easier to debug (lol).
The problem is not with exceptions, but with checked exceptions. Like a lot of things with programming, they sound much better in theory than they actually appear in practice. I've lost count the times I've seen them abused in actual production code.
"Handling" them like these is not suboptimal use, it's a recipe for disaster:
try{ whatever(); }catch( InterruptedException e ){ // trololo do nothing, let other threads suffer }catch( IOException e ){ logger.log("This isn't actually proper handling"); }catch( NoMessageInThisException e ){ throw new RuntimeException("Mwahahaha, no stacktrace for you: " + e.getMessage()); }catch( NumberFormatException e ){ throw new RuntimeException("You won't catch me, hahaha!", e); }catch( SomeCommonException e ){ e.printStacktrace(); // trololo we don't actually log stdout or stderr }catch( YetAnotherExceptionBecauseThereAreNotEnoughCatchClauses e ){ some; complicated; error; handling; just to; make the code unreadable; } // no finally block whatsoever, we don't need releasing any resources after all
The only reasonable explanation I have found for the existence of checked exceptions, is that they designed them to be alternative return values for a method. Every other explanation is smoke and mirrors.
|
|
|
On March 29 2013 07:23 Frigo wrote:Show nested quote +On March 29 2013 07:00 RoyGBiv_13 wrote:On March 29 2013 06:47 Frigo wrote:try { ugly method call throwing checked exception }catch( Exception e ){ rethrow(e); }Where rethrow(Exception e) is a n ugly nice hack exploiting type erasure to be able to throw checked exception without actually declaring them in a throws exception. Much much better than swallowing it, which is plain disgusting, or rethrowing it as RuntimeException, which you can't catch properly at higher levels. Exception structures may be ugly/hackish and difficult to use effectively, but I just think of the alternatives and shudder. HealthMonitors and run-time error checking are kind of a bust. I often just let my kernel panic and core dump than have to deal with a health monitor. Easier to debug (lol). The problem is not with exceptions, but with checked exceptions. Like a lot of things with programming, they sound much better in theory than they actually appear in practice. I've lost count the times I've seen them abused in actual production code. "Handling" them like these is not suboptimal use, it's a recipe for disaster: try{ whatever(); }catch( InterruptedException e ){ // trololo do nothing, let other threads suffer }catch( IOException e ){ logger.log("This isn't actually proper handling"); }catch( NoMessageInThisException e ){ throw new RuntimeException("Mwahahaha, no stacktrace for you: " + e.getMessage()); }catch( NumberFormatException e ){ throw new RuntimeException("You won't catch me, hahaha!", e); }catch( SomeCommonException e ){ e.printStacktrace(); // trololo we don't actually log stdout or stderr }catch( YetAnotherExceptionBecauseThereAreNotEnoughCatchClauses e ){ some; complicated; error; handling; just to; make the code unreadable; } // no finally block whatsoever, we don't need releasing any resources after all
The only reasonable explanation I have found for the existence of checked exceptions, is that they designed them to be alternative return values for a method. Every other explanation is smoke and mirrors.
The explanation isn't smoke and mirrors, (checked) exceptions exist to guarantee certain invariants in the code. But like every code structure, when misused it sucks. I guess the grass is greener...
+ Show Spoiler +If you think that code snippet is bad. To write a Health Monitor for one of my (customer's)programs, I had to write a monitor at the task-level, application-level, and system-level just to catch one exception. Instead of horrible ugly code for each dangerous function call, you have horribly ugly code which does voodoo XFrame magic and virtual-to-physical page mapping just to get the stack frame present. This code has to be rewritten in every abstracted layer of the program. The worst part of it all is that in systems where a health monitor actually *is* a good idea, the most common problems are in the drivers which the health monitor can't detect. + Show Spoiler +So complain all you want that handling exceptions sucks ass, because writing code to generate them is like the dyson colon vacuum or ass sucking
|
Hey
So I am working on a noob version of a UI system with windows you can move around (written in c++ with SDL). Now that part works. I store every window in a vector and then when the left mouse button is pressed I go through the vector and check if it's inside any of the windows. Now this is the part where I get stuck.
It is impossible for me to figure out how not to be able to select a window behind the one in front because I have at no point the ability to make sure that the one I'm inside is the "focused" one, because I can never set which one is the focused one since I might be inside two windows at the same time. And if i click where I am inside two windows, the one after the other in the list will be the one that gets picked.
If someone could lend some advice that would be great. :/ Thanks
|
On March 29 2013 20:23 Nausea wrote: Hey
So I am working on a noob version of a UI system with windows you can move around (written in c++ with SDL). Now that part works. I store every window in a vector and then when the left mouse button is pressed I go through the vector and check if it's inside any of the windows. Now this is the part where I get stuck.
It is impossible for me to figure out how not to be able to select a window behind the one in front because I have at no point the ability to make sure that the one I'm inside is the "focused" one, because I can never set which one is the focused one since I might be inside two windows at the same time. And if i click where I am inside two windows, the one after the other in the list will be the one that gets picked.
If someone could lend some advice that would be great. :/ Thanks
Add a layering (ie. z-order) system. Each window has a integer layer attribute, and the larger the number the more 'on-top' it is. And the window you'd be clicking is the topmost one.
|
On March 29 2013 20:34 ddengster wrote:Show nested quote +On March 29 2013 20:23 Nausea wrote: Hey
So I am working on a noob version of a UI system with windows you can move around (written in c++ with SDL). Now that part works. I store every window in a vector and then when the left mouse button is pressed I go through the vector and check if it's inside any of the windows. Now this is the part where I get stuck.
It is impossible for me to figure out how not to be able to select a window behind the one in front because I have at no point the ability to make sure that the one I'm inside is the "focused" one, because I can never set which one is the focused one since I might be inside two windows at the same time. And if i click where I am inside two windows, the one after the other in the list will be the one that gets picked.
If someone could lend some advice that would be great. :/ Thanks Add a layering (ie. z-order) system. Each window has a integer layer attribute, and the larger the number the more 'on-top' it is. And the window you'd be clicking is the topmost one.
When would I set these? I mean, if I would set the one I'm clicking on as the top then if that window is over another window at the time, would that not lead to both of those being set to the top? And I don't understand where I would get the chance to set the other windows z to adjust to the top one. :/
example: One window is the top one, I then drop that and pick another window and set it to the top one. How will I be able to set the last top window to a higher z at that point.
|
On March 29 2013 20:59 Nausea wrote:Show nested quote +On March 29 2013 20:34 ddengster wrote:On March 29 2013 20:23 Nausea wrote: Hey
So I am working on a noob version of a UI system with windows you can move around (written in c++ with SDL). Now that part works. I store every window in a vector and then when the left mouse button is pressed I go through the vector and check if it's inside any of the windows. Now this is the part where I get stuck.
It is impossible for me to figure out how not to be able to select a window behind the one in front because I have at no point the ability to make sure that the one I'm inside is the "focused" one, because I can never set which one is the focused one since I might be inside two windows at the same time. And if i click where I am inside two windows, the one after the other in the list will be the one that gets picked.
If someone could lend some advice that would be great. :/ Thanks Add a layering (ie. z-order) system. Each window has a integer layer attribute, and the larger the number the more 'on-top' it is. And the window you'd be clicking is the topmost one. When would I set these? I mean, if I would set the one I'm clicking on as the top then if that window is over another window at the time, would that not lead to both of those being set to the top? And I don't understand where I would get the chance to set the other windows z to adjust to the top one. :/
Initially, you'd want to make sure to have a rule that each window has a specific z-layer when you create them. Assuming you're trying to simulate the way windows in windows(nice pun) works, you set the layer to the largest unoccupied z-layer value when you create it. That way, when you click on an area where 2 windows intersect, they're guaranteed to have unique z-layers, and you just get the one with the largest z-layer.
Anyway, these rules are really up to you to define, don't take my word for it and apply it to everything else; you can adjust these things for your needs.
|
To answer your example, you can change the z-values to some unique value (something which you know you will probably never hit)when you 'drop' it. And you could loop over all the windows for the highest z values and assign the next highest z to the window you want. Or even define a 'highest' z value that the whole UI system follows.
|
On March 29 2013 21:17 ddengster wrote: To answer your example, you can change the z-values to some unique value (something which you know you will probably never hit)when you 'drop' it. And you could loop over all the windows for the highest z values and assign the next highest z to the window you want. Or even define a 'highest' z value that the whole UI system follows.
Thank you. I got another answer on gamedev which I think I will try.
"Instead of storing the window pointers in a vector, store them in the list. Mouse testing is then done from top to bottom, and drawing is done from bottom to top. Moving a window to the top requires that the window be removed and added to the front of the list."
|
Does anyone in here have any experience writing Firefox plug-ins? I'm completely lost. I've got a plugin that will alert "hi" when a menu item is clicked, and I've read through the XUL School tutorial, which explains how to create and configure a plugin, but I can't figure out how to interact with the current document in even the most basic way, or how to get debugging to work on Javascript in the plug-in. The tutorial says Venkman will do it, but the tutorial is quite old and as near as I can tell the way it claims debugging can be done is no longer possible.
Anyone think they could help me out? I'd be thrilled if I could even get as far as getting a reference to the document object - once I've got that I'm golden.
-- Edit: I finally posted this after being lost for nearly two weeks, then randomly figured out the exact right Google search to get the information I wanted. From the context of an extension, the currently loaded document is content.document, not window.document.
|
I'm interested in learning the OOP part of C++, but I'd rather not spend money right now. I think I'd settle with some basic/medium knowledge and getting comfortable with the language. However, I'm not sure which tutorial is for me.
http://www.cplusplus.com/doc/tutorial/
Is this one alright? I already have some C knowledge, and more on Java too.
Edit: Something unrelated (CSS):
http://i.imgur.com/Q3cUg29.gif
|
On March 30 2013 05:56 darkness wrote:I'm interested in learning the OOP part of C++, but I'd rather not spend money right now. I think I'd settle with some basic/medium knowledge and getting comfortable with the language. However, I'm not sure which tutorial is for me. http://www.cplusplus.com/doc/tutorial/Is this one alright? I already have some C knowledge, and more on Java too. Edit: Something unrelated (CSS): http://i.imgur.com/Q3cUg29.gif Try C++ Primer Plus 5th edition. Pretty easy to find copies for free around the internet.
|
On March 30 2013 07:42 CecilSunkure wrote:Show nested quote +On March 30 2013 05:56 darkness wrote:I'm interested in learning the OOP part of C++, but I'd rather not spend money right now. I think I'd settle with some basic/medium knowledge and getting comfortable with the language. However, I'm not sure which tutorial is for me. http://www.cplusplus.com/doc/tutorial/Is this one alright? I already have some C knowledge, and more on Java too. Edit: Something unrelated (CSS): http://i.imgur.com/Q3cUg29.gif Try C++ Primer Plus 5th edition. Pretty easy to find copies for free around the internet.
I've found it. Thanks.
|
|
|
|
|
|