Is there a way to stop MonoDevelop de-indenting Loop Identifiers by one step? I'm writing in D using MonoDevelop 5.0.1 with Mono-D 2.1.9 on Ubuntu 12.04 LTS.
Whenever I give a loop an identifier so it can be broken or continued in another nested loop it always de-indents the line with the loop statement by one step, breaking consistency with everything else. This probably looks much better if you but braces on newlines but I don't and I'm not about to change my entire workflow for one annoying formatting quirk.
Here's an example of what I'm talking about:
void functionName() {
dosomething();
foreach(Object o; array1) { //<- indents correctly if it doesn't have an identifier
o.dosomethng();
}
outer: foreach(Object o; array2) { //<- always indents one step back if identifier present
o.dosomething();
}
}
Is there a way to disable the behaviour? Nothing in Edit->Preferences->Code Formatting seems to say anything about it either for D or C#
This seems like a bug in Mono-D AddIn probably somewhere inside this code: https://github.com/aBothe/Mono-D/blob/master/MonoDevelop.DBinding/Formatting/Indentation/DTextEditorIndentation.cs
I suggest you to report bug on Mono-D AddIn issue tracker at https://github.com/aBothe/Mono-D/issues or checkout Mono-D AddIn source code fix bug and make pull request. ;)
Related
So I am working on this side project game kinda thing, and I want to put it inside of a border/box. I then want to print text constantly inside that border: adding text, removing it, changing it etc. I've looked far and wide, and cannot find anyway to print inside the box separately from the actual box.
My current implementation is to clear screen, and then reprint the entire box with new text using this:
printf("\e[1;1H\e[2J");
The issue with this is that I get this very obnoxious blinking effect, because every iteration of clearing my screen causes that portion of the screen to become black for a certain period of time.
So I am looking for a few solutions.
How to print a border separate from the print statement inside of it. I currently am implementing it like such:
printf("| | Hello There ||\n");
, and then repeating that all the way down to make a border.
How to completely overwrite the already outputted text so that this blinking effect can go away. So imagine \r removing a line, I want something like that, that removes the whole text and replaces it with a new set of text
How to change the location of where the user inputs into the console, so you can type into a box
Those are basically the only solutions I could think of, if you have any others I'd love to hear them
I also had a general question about c.
conio.h, graphics.h, windows.h and a few other headers don't work for my compilers. I use ubuntu, and they always come up with some error saying I can't use them. I appreciate someone explaining this to me.
Please let me know what you think, and if you need more info, I'll be sure to provide it
-Ryan
conio.h and windows.h are not standard Linux libraries, so they won't compile on Linux unless you install extra software. One solution would be to use a library designed for managing the screen like ncurses.
You can do that with loops and ASCII characters similar like that:
#include <stdio.h>
int main()
{
int i;
printf("\n\t\t═");
for(i=0;i<=20;i++)
{
printf("═");
}
for(i=0;i<=22;i++)
{
printf("\t\t║\n");
if(i==10)
{
printf("\t\t\tHello There \t\n");
}
printf("\t\t\t\t\t║\n");
}
printf("\t\t═");
for(i=0;i<=22;i++)
{
printf("═");
}
return 0;
}
I've added this line to hook_preprocess_page in template.php:
if (isset($vars['node']) && $vars['node']->type=='landing_page') {
$vars['theme_hook_suggestions'][] = 'page__'. $vars['node']->type;
}
This worked fine on my test server however now I have put it on staging and has caused:
A) Only the page template is output - it is not surrounded by html.tpl.php.
B) My preprocess_html function in template.php is not being called at all.
If I comment out the line then html.tpl.php is used again.
This thread is discussing similar but opposite problem.
I'm really stumped on this - any points would be really useful!
This was being caused by calling an undefined function in my page template.
This wasn't apparent until I started searching the error logs.
Hope this may save someone else some time...
I found two lines in my code.
test = new qx.ui.form.RadioGroup;
I am wondering, if the missing () might cause issues or should maybe raise a warning in the generator or the lint job.
qx.ui.form.RadioGroup;
I think it might be worth reporting it as a "statement without effect" in lint.
mck89's comment is the answer (I wonder why so many people put valid answers in comments...):
You don't need the parens, and new qx.ui.form.RadioGroup is a syntactically correct expression, equivalent to adding a pair of empty parens. (There are some checkers that will warn about this, like I believe JsLint, but qooxdoo doesn't ... :).
In your particular case, the code will also run successfully in the browser, as RadioGroup permits empty constructor args; you can use .add() later to add items to the group.
I took over an incomplete project and to my utter disbelieve, every single function is wrapped with try-catch statements in this same format:
try
{
// work work.
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, ...);
}
As I search SO for a method to quickly remove all these try-catch blocks, I find that people are actually looking for method to automatically wrap their functions with try-catch! hmmm... Is that good programming practice at all? Is there is method to remove all blocks instead so that it makes debugging easier and allows me to really solve the exceptions?
You can change the option here:
Debug -> Exceptions -> CLR Exceptions -> Check the "Thrown" checkbox.
This causes the compiler to break whenever an exception is thrown, before checking any catch blocks.
This is a horrible programming practice. I once saw this as a bug mess up someone's database.
It is my firm opinion you are better off letting your program die a fiery death than mindlessly continue on in an unknown state.
I would do a find and replace on MessageBox.Show(ex with throw //MessageBox.Show(ex and replace them all. You will have to manually find the ones that should really be there and put them back.
Visual Studio's Regex search is pretty powerful, however it is a bit tricky to use, here is something that you might find useful in searching for your above code: (Note in the find dialog box, in the Options section choose "Use: Regular Expressions")
Will find your bad catches:
catch.*\n+:b+{[.:b\n]MessageBox.[.:b\n]*}
If you want to do a straight replace with a throw:
catch\n{\nthrow;\n}
I've discovered a solution to this for VB.NET.
Replace this:
\s(?<!End )Try((.|\r\n)+?)Catch(.|\r\n)+?(Finally((.|\r\n)+?)End Try|End Try)
...with this:
$1$5
It will remove the entire try/catch block while leaving behind only what was in the try and finally blocks. It doesn't work with nested try/catches, though, so you'd need to replace the nested blocks first and then the outer blocks last.
Quick and dirty trick:
search & replace try -> if(true) //WAS TRY
search & replace catch§ -> if(true) //WAS CATCH §
§ is a placeholder for the regex to match what is catched and put it after the comment WAS CATCH
by this way you can:
revert searching WAS TRY and WAS CATCH §
decide what has to be replaced and what has not when during rhe search
I use to comment with // DUMMY every catch that is temporary during the debug session.
(since this is a very old post, I didn't take all the time needed to write the regex etc... please be patient)
This question already has answers here:
Closed 13 years ago.
Possible Duplicates:
Formatting of if Statements
Is there a best coding style for identations (same line, next line)?
Best way to code stackoverflow style 'questions' / 'tags' rollover buttons
public void Method {
}
or
public void Method
{
}
Besides personal preference is there any benefit of one style over another? I used to swear by the second method though now use the first style for work and personal projects.
By readability I mean imagine code in those methods - if/else etc...
Google C++ Style Guide suggests
Return type on the same line as function name, parameters on the same line if they fit.
Functions look like this:
ReturnType ClassName::FunctionName(Type par_name1, Type par_name2) {
DoSomething();
...
}
WebKit Coding Style Guidelines suggests
Function definitions: place each brace on its own line.
Right:
int main()
{
...
}
Wrong:
int main() {
...
}
They suggest braces-on-same-line for everything else, though.
GNU Coding Standards suggests
It is important to put the open-brace that starts the body of a C function in column one, so that they will start a defun. Several tools look for open-braces in column one to find the beginnings of C functions. These tools will not work on code not formatted that way.
Avoid putting open-brace, open-parenthesis or open-bracket in column one when they are inside a function, so that they won't start a defun. The open-brace that starts a struct body can go in column one if you find it useful to treat that definition as a defun.
It is also important for function definitions to start the name of the function in column one. This helps people to search for function definitions, and may also help certain tools recognize them. Thus, using Standard C syntax, the format is this:
static char *
concat (char *s1, char *s2)
{
...
}
or, if you want to use traditional C syntax, format the definition like this:
static char *
concat (s1, s2) /* Name starts in column one here */
char *s1, *s2;
{ /* Open brace in column one here */
...
}
As you can see, everybody has their own opinions. Personally, I prefer the Perl-ish braces-on-same-line-except-for-else, but as long as everybody working on the code can cooperate, it really doesn't matter.
I think it is completely subjective, however, I think it is important to establish code standards for your team and have everyone use the same style. That being said I like the second one (and have made my team use it) because it seems easier to read when it is not your code.
In the old days we used to use the first style (K & R style) because screens were smaller and code was often printed onto this stuff called paper.
These days we have big screen and the second method (ANSI style) makes it easier to see if your brackets match up.
See HERE and HERE for more information.
First one is smaller in terms of number of lines (maybe that is why development -Java- books tend to use that syntax)
Second one is, IMHO easier to read as you always have two aligned brackets.
Anyway both of them are widely used, it's a matter of your personal preferences.
I use the if statement as something to reason on in this highly emotive subject.
if (cond) {
//code
}
by just asking what does the else statement look like? The logical extension of the above is:-
if (cond) {
//code
} else {
//more code
}
Is that readable? I don't think so and its just plain ugly too.
More lines is != less readable. Hence I'd go with your latter option.
Personally I find the second one more readable (aligned curlys).
Its always easiest for a team to go with the defaults, and since Visual Studio and I agree on this, thats my argument. ;-)
Your lines of code count will be considerably less with the first option. :)