Dear list,
the default snippets that are installed to prefix/share/geany/snippets.conf have C/C++ code in the [default] section.
This can lead to C/C++ code in a Fortran file. In the patch attached to this mail, I reorganized the snippets. Default behaviour should not change with this patch [1].
Thanks for taking care.
Sincerely,
Alex
[1]: One exception: people could insert a C++ try{} block into a C. This is not possible anymore.
Hi,
On Thu, 25 Aug 2011 17:47:21 +0200 "Alexander Eberspächer" alex.eberspaecher@gmail.com wrote:
the default snippets that are installed to prefix/share/geany/snippets.conf have C/C++ code in the [default] section.
This can lead to C/C++ code in a Fortran file. In the patch attached to this mail, I reorganized the snippets. Default behaviour should not change with this patch [1].
I disagree at this point as discussed on IRC: The current patch will remove support for if, else, while, do and switch PHP, Java and C++ and maybe other C-like languages. At least on the main language we have to improve the patch a bit or it will leat to missing feature for users.
(Nevertheless I like the idea to don't have C inside != C-like language -- only I'm thinking the patch does not fit the needings ;) )
Cheers, Frank
Hello list,
On Thu, 25 Aug 2011 18:16:26 +0200 Frank Lanitz frank@frank.uvena.de wrote:
The current patch will remove support for if, else, while, do and switch PHP, Java and C++ and maybe other C-like languages. At least on the main language we have to improve the patch a bit or it will leat to missing feature for users.
That's right. I didn't think that through.
I attached a newer patch that adds the former [default] functionality to the C-like languages C, C++, C#, Java, PHP, D. Hopefully I respected subtle differences for D.
This shall remove the default snippets bias towards C-like languages. However, the patch will break default snippets for other C-like languages (if there are any supported by Geany at all).
I hope this patch fits the needs a bit better.
Cheers
Alex
On 08/25/2011 09:49 AM, Alexander Eberspächer wrote:
Hello list,
I hope this patch fits the needs a bit better.
Hi Alex,
For C# (and probably C++ ?), the for loop should probably be more like D and Java (ie. `for (int i=0; ...`).
Also, Python should not have `for i in xrange(...)` since it has been removed from Python 3 and this type of loop is considered "bad style" even in Python 2.
I know these aren't from your patch, but since you're fixing up the snippets file :)
Cheers, Matthew Brush
Dear Matthew, dear list,
On Thu, 25 Aug 2011 18:02:20 -0700 Matthew Brush mbrush@codebrainz.ca wrote:
For C# (and probably C++ ?), the for loop should probably be more like D and Java (ie. `for (int i=0; ...`).
Changed that, it's now `for (int i; ...)`.
Also, Python should not have `for i in xrange(...)` since it has been removed from Python 3 and this type of loop is considered "bad style" even in Python 2.
Changed it to `range()`.
I know these aren't from your patch, but since you're fixing up the snippets file :)
Some other changes in the most recent patch (find it attached to this mail):
I removed the [Haskell] section that only prevented the default completion of do loops in Haskell.
I added both LaTeX and Fortran snippets. The Fortran snippets add similar snippet functionality as is already present for the C-like languages. The LaTeX snippets provide standard LaTeX functionality probably needed by any LaTeX user. None of the LaTeX commands depends on external packages.
Maybe the patch is a first step towards better default snippets.
Cheers,
Alex
[...]
Hi Alex,
Nice job.
My 0.5c worth, in C++ it is important to pre-increment unless you really need the previous value since post increment could create a wasted expensive copy of an object. Although an int isn't expensive, it is probably better to make it ++i in the for loop so it agrees with the usual idiom.
Cheers Lex
Dear Lex, dear list,
On Fri, 26 Aug 2011 20:39:38 +1000 Lex Trotman elextr@gmail.com wrote:
My 0.5c worth, in C++ it is important to pre-increment unless you really need the previous value since post increment could create a wasted expensive copy of an object. Although an int isn't expensive, it is probably better to make it ++i in the for loop so it agrees with the usual idiom.
I changed that for C++ (revised patch attached).
Now that we go into details, let's briefly discuss assumptions being made by those snippets:
The snippets for the loops assume that the counting variable is shall be i. Furthermore, it is assumed that i was not declared before. This seems to work for most people, however, I personally would opt for completion of
"do"
to
"for (%cursor%) {
}"
In this case, the name of the counting variable is to be filled in by the user (I left that decision to the user in the Fortan snippets, too [1]). Changing the snippets towards less assumptions changes Geany's default behaviour.
So, what do we want here? Anyone else +1 for less assumptions about what the user wants?
Cheers
Alex
[1] Considering that Fortran is mostly used in scientific computing, I think it is reasonable to assume that `i` is not the variable the user wants to loop over.
On 26 August 2011 20:57, Alexander Eberspächer alex.eberspaecher@gmail.com wrote:
Dear Lex, dear list,
On Fri, 26 Aug 2011 20:39:38 +1000 Lex Trotman elextr@gmail.com wrote:
My 0.5c worth, in C++ it is important to pre-increment unless you really need the previous value since post increment could create a wasted expensive copy of an object. Although an int isn't expensive, it is probably better to make it ++i in the for loop so it agrees with the usual idiom.
I changed that for C++ (revised patch attached).
Now that we go into details, let's briefly discuss assumptions being made by those snippets:
The snippets for the loops assume that the counting variable is shall be i.
Thats traditional...
Furthermore, it is assumed that i was not declared before.
For C++ its fine to re-declare i within the loop, it will hide any external declaration.
This
seems to work for most people, however, I personally would opt for completion of
"do"
to
"for (%cursor%) {
}"
Thats a bit counter-intuitive since there is a do statement, and it is post tested rather than pre-tested like for. Maybe use something else for for two (pun intended :) or change the original
In C++ it is more common than in C to use other loop operations (eg iterators) not just simple counters, so maybe the blank version would be better as the main for entry for C++.
In this case, the name of the counting variable is to be filled in by the user (I left that decision to the user in the Fortan snippets, too [1]). Changing the snippets towards less assumptions changes Geany's default behaviour.
Maybe you should preserve default behavior on the basis that someone decided it to be that way, unless you know no one cares.
For C++ IIUC it just works like C because thats what Geany is written in.
So, what do we want here? Anyone else +1 for less assumptions about what the user wants?
Cheers
Alex
[1] Considering that Fortran is mostly used in scientific computing, I think it is reasonable to assume that `i` is not the variable the user wants to loop over.
I dunno, all the sigmas I remember used i & j, and in original fortran all variables starting with i to n were integers, so again tradition has it to use i,j,k,l,m,n.
Cheers Lex
PS You seem to have got a copy of the for entry tacked on to the end of the switch snippet for C++ & C# PPS there seem to be line breaks in some entries, (eg switch) entries must be on one line
Hey Lex, hello list,
On Fri, 26 Aug 2011 22:04:01 +1000 Lex Trotman elextr@gmail.com wrote:
The snippets for the loops assume that the counting variable is shall be i.
Thats traditional...
But still making a rather strong assumptions about what the user wants.
For C++ its fine to re-declare i within the loop, it will hide any external declaration.
Okay, didn't remember that. Is that true for C# and Java also?
seems to work for most people, however, I personally would opt for completion of
"do"
to
"for (%cursor%) {
}"
Thats a bit counter-intuitive since there is a do statement, and it is post tested rather than pre-tested like for. Maybe use something else for for two (pun intended :) or change the original
Of course I meant "for" to be completed - I was creating to patch while I wrote some Fortran code, and in Fortran C's 'for' is basically 'do' :/ Sorry for the confusion.
In C++ it is more common than in C to use other loop operations (eg iterators) not just simple counters, so maybe the blank version would be better as the main for entry for C++.
Any other opinions on that? Your suggestions breaks consistency with C/C#/PHP...
Maybe you should preserve default behavior on the basis that someone decided it to be that way, unless you know no one cares.
I want to make my point about assumptions a bit clearer: if a user writes 'for' in C program and hits the completion key, one can be sure that this user wants a for loop. However, you cannot (and IMHO, to keep snippets useful for any user, must not) be sure that the user wants 'i' to be the counting variable.
So, what do other people think? The patch should not break what people actually use. However, a *consistent* set of snippets uses either a default counting variable for all languages or doesn't fill in any at all.
I dunno, all the sigmas I remember used i & j, and in original fortran all variables starting with i to n were integers, so again tradition has it to use i,j,k,l,m,n.
That's Fortran 77. From Fortran 90 on, there is the 'implicit none' statement that tells the compiler not to use implied types. I've already added a snippet for that.
PS You seem to have got a copy of the for entry tacked on to the end of the switch snippet for C++ & C#
Oops. Fixed (patch attached).
PPS there seem to be line breaks in some entries, (eg switch) entries must be on one line
Can't see any line breaks.
So I hope there will be some discussion on what the default snippets should do. I am happy to create a patch that does just whatever the discussion results in.
Cheers
Alex
On 26 August 2011 22:49, Alexander Eberspächer alex.eberspaecher@gmail.com wrote:
Hey Lex, hello list,
On Fri, 26 Aug 2011 22:04:01 +1000 Lex Trotman elextr@gmail.com wrote:
The snippets for the loops assume that the counting variable is shall be i.
Thats traditional...
But still making a rather strong assumptions about what the user wants.
As I said below, in C++ there are more options that don't use a simple counter, so IMHO the fully blank for you suggested would be better for C++ rather than caring what a counter is called.
For C++ its fine to re-declare i within the loop, it will hide any external declaration.
Okay, didn't remember that. Is that true for C# and Java also?
Don't know them enough.
[...]
Any other opinions on that? Your suggestions breaks consistency with C/C#/PHP...
Well I thought part of the reason for separating them into individual languages was so each could be customised for the language, there is no reason for them to be the same.
Maybe you should preserve default behavior on the basis that someone decided it to be that way, unless you know no one cares.
I should be more clear too, I mean that where there is a specific snippet for a language lets get other opinions before changing the behavior. For things that were default and are now language specific, then there is no problem with customising it to suit the language.
I want to make my point about assumptions a bit clearer: if a user writes 'for' in C program and hits the completion key, one can be sure that this user wants a for loop. However, you cannot (and IMHO, to keep snippets useful for any user, must not) be sure that the user wants 'i' to be the counting variable.
The more I think about it the more options there are for C as well, eg null terminated for(p=something; *p; p++), linked for(p=something; p; p=p->next) as well as the counter so I don't know, maybe C should be blank as well, after all the if, while and do while are blank, or maybe for(%cursor%; %cursor%; %cursor% )?
So, what do other people think? The patch should not break what people actually use. However, a *consistent* set of snippets uses either a default counting variable for all languages or doesn't fill in any at all.
IMHO consistency between languages is less important than being most appropriate for the language. Files can only have one filetype so you can't see the inconsistencies between languages without switching files anyway.
I dunno, all the sigmas I remember used i & j, and in original fortran all variables starting with i to n were integers, so again tradition has it to use i,j,k,l,m,n.
That's Fortran 77. From Fortran 90 on, there is the 'implicit none' statement that tells the compiler not to use implied types. I've already added a snippet for that.
Of course you shouldn't use implicit types, but there is lots of existing code and a practice that indexes are i,j, etc
PS You seem to have got a copy of the for entry tacked on to the end of the switch snippet for C++ & C#
Oops. Fixed (patch attached).
PPS there seem to be line breaks in some entries, (eg switch) entries must be on one line
Can't see any line breaks.
Ok, just me being confused by Gedits line wrapping (thats what patch attachments default open in, I must change that to Geany).
Cheers Lex
So I hope there will be some discussion on what the default snippets should do. I am happy to create a patch that does just whatever the discussion results in.
Cheers
Alex _______________________________________________ Geany-devel mailing list Geany-devel@uvena.de https://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel
Le 26/08/2011 14:49, Alexander Eberspächer a écrit :
Hey Lex, hello list,
On Fri, 26 Aug 2011 22:04:01 +1000 Lex Trotman elextr@gmail.com wrote:
Maybe you should preserve default behavior on the basis that someone decided it to be that way, unless you know no one cares.
I want to make my point about assumptions a bit clearer: if a user writes 'for' in C program and hits the completion key, one can be sure that this user wants a for loop. However, you cannot (and IMHO, to keep snippets useful for any user, must not) be sure that the user wants 'i' to be the counting variable.
So, what do other people think? The patch should not break what people actually use. However, a *consistent* set of snippets uses either a default counting variable for all languages or doesn't fill in any at all.
I agree that the current snippets do too much assumptions on what the user wants: I personally generally don't want the default "for" behavior, because I don't only iterate over an "i" variable from 0 to n.
So IMHO it's a good idea to have more generic snippets, maybe for C's "for" something like:
for (%cursor%; %cursor%; %cursor%)%block_cursor%
or even your suggested one:
for (%cursor%)%block_cursor%
if typing the semicolons feels more natural than moving in the snippet.
PPS there seem to be line breaks in some entries, (eg switch) entries must be on one line
Can't see any line breaks.
So I hope there will be some discussion on what the default snippets should do. I am happy to create a patch that does just whatever the discussion results in.
Just a comment on the patch, based on a cursory reading: please use [Special] whenever possible to let the user choose her newline & co policy. For example, the "do" snippet:
do=do\n{\n\t%cursor%\n} while (%cursor%)\n%cursor%
should use at least %brace_open% in place of "\n{\n\t", and probably even %block%:
do=do%block% while (%cursor%)\n%cursor%
BTW, it also misses the final semicolon:
do=do%block% while (%cursor%);\n%cursor%
Regards, Colomban
Hi,
I've got a comment to LaTeX:
On Fri, 26 Aug 2011 11:31:40 +0200 "Alexander Eberspächer" alex.eberspaecher@gmail.com wrote:
+figure=\begin{figure}\n\t\centering\n\t\includegraphics[]{%cursor%} \n\t\caption{}\n\t\label{fig:}\n\end{figure}
I'd like to leave the centering here out.
Cheers, Frank