Thursday, December 19, 2013

Re: first parsing steps : request for comments


On Dec 19, 2013 5:21 PM, "Marcin Szamotulski" <mszamot@gmail.com> wrote:
>
> On 13:23 Thu 19 Dec     , Alexandre Hoïde wrote:
> >   Hello,
> >
> >   Still working my way to yellow belt in the Vim Scripting Art, I come
> > to you with a little piece of code I wrote to later serve in a plugin
> > I'm trying to write (to work with GNU Gettext PO files). I would be
> > interrested in comments from >= yellow belt Vim Scripters to improve my
> > code and my skills. And I have to say, i find my 'get_line' function
> > ugly. ^^
> >
> >   I think (hope) the attached code is rather self-explanatory, and
> > there's also a small sample 'po' file on which this code is supposed to
> > work. This will be the plugin first step at parsing a PO file.
> >
> >   Regards,
>
> It is better to not use regular expressions when there are not really
> needed so I would change this line:
>     if a:key !~# '^\(first\|last\)$'
> into
>     if a:key != 'first' && a:key != 'last'

Never use ==/!=/=~/!~ for string comparison. The OP is absolutely right using !~# and you should change this to !=# or isnot#. Otherwise you are depending on &ignorecase option value.

> or
>     if index(['first', 'last'], a:key) == -1
> which is nice if you have more items than just two, but it's maybe worth
> to mention.
>
>
> You can avoid using eval in the line:
>     let ldict = eval('self.' . a:key)
> with:
>     let ldcit = self[a:key]
>
> I also would not store an expression in a dictionary (like 'deferred')
> but move it to get_line to avoid using eval.
>
> Best regards,
> Marcin
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
 
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment