[Geany-devel] Default snippets

Lex Trotman elextr at xxxxx
Fri Aug 26 12:04:01 UTC 2011

On 26 August 2011 20:57, Alexander Eberspächer
<alex.eberspaecher at gmail.com> wrote:
> Dear Lex, dear list,
> On Fri, 26 Aug 2011 20:39:38 +1000
> Lex Trotman <elextr at 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.

> 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.


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

More information about the Devel mailing list