News for hackers. Stuff that matters.
Re:Vim 7.3.1000 by tsm on Tuesday May 21, 2013 @05:02PM (#5746814)
I guess I should be thankful 98% of my programming life is in higher-level languages than C, but...am I the only one whose terrified of the magic numbers? In hex? Can anyone provide context about what's so special about 0xfb20 and 0xfb4f?
Re:Vim 7.3.1000 by goldfeld on Tuesday May 21, 2013 @05:16PM (#5746893)
All my programming life has been in higher-level languages, yet with Rust I'm being inexplicably drawn to down and dirty systems programming. It's cool to finally be able to use :make and all the C-oriented things like [i and ]i, ctags and the like. It's interesting seeing how much 'dogfooding' vim has in that tons of stuff are undoubtedly geared towards his own needs developing vim (and C applications in general.) Pretty much how I work with coding products, I work my best when I'm the use case, and great open source products like vi/vim and emacs excel in that legions of people share the creator's use case (and well, configurability right down to the bone.) I've found that a non-trivial amount of people do share the use case for the first project I've launched[1], I only hope for it to hold true for my most ambitious ones in the working.

I don't know Bram, but I can't help but wonder why such a distinguished open source figure has ultimately ended up working for Google. Maybe he enjoys the access to resources. I wish donations could still support him directly rather than his idea of aid (well it does seem to have a bend towards education at least). I wish he wouldn't need a day job and could yet breed other new and great contributions to the world. I don't feel particularly endeared towards Google, despite all the collateral good it has done while doing a lot of evil (i.e. something to do with the looming ad empire strengthening big corporations.)

[1]: https://github.com/goldfeld/vim-seek

Re:Vim 7.3.1000 by gbog on Tuesday May 21, 2013 @11:17PM (#5748661)
I use ctags with Python, PHP and I'm sure it will works with most other languages invented.
Re:Vim 7.3.1000 by meritt on Tuesday May 21, 2013 @05:18PM (#5746912)
http://www.unicode.org/versions/Unicode6.2.0/ch08.pdf page 250

Screenshot of relevant text: http://i.imgur.com/xMnHDg4.png

Basically certain Hebrew characters have descenders which can overlap with diatric marks in the next line of text. These variations are suitable replacements that alter it slightly so it won't overlap.

Re:Vim 7.3.1000 by IvyMike on Tuesday May 21, 2013 @07:11PM (#5747703)
I'd so prefer to see

  #define HEBREW_CHAR_MIN 0xfb20
  #define HEBREW_CHAR_MAX 0xfb4f
(Probably with even more descriptive names, but I don't know the problem domain.)
Re:Vim 7.3.1000 by redcircle on Tuesday May 21, 2013 @07:33PM (#5747817)
It is nice to move away from the C preprocessor:

enum { HebrewCharMin=0xfb20, HebrewCharMax=0xfb4f, };

Re:Vim 7.3.1000 by srl on Tuesday May 21, 2013 @10:54PM (#5748568)
Can you explain why this is preferable to using the preprocessor? I've always considered it a pretty fundamental principle that the "surface" interpretation of code should be as close as possible to the "real" meaning, and we're definitely not trying to represent an "enumeration". What's wrong with #define, or `const uint32_t HebrewCharMin...`?
Re:Vim 7.3.1000 by IvyMike on Wednesday May 22, 2013 @01:04AM (#5748999)
I'd argue that in good old C, #defines for pure constants are pretty well established and considered idiomatic. In other words, I wouldn't ding it in a code review. (Nor would I ding the enum solution. Either one is perfectly cromulent.) In some ways, even though we now have better alternatives in C, I kinda feel like any C tool and any C programmer had better be able to deal with #define constants. Quickly browsing the vim source, it looks like they have seem to default to using #define for constants, and "when in Rome" is a good rule of thumb to live by. :)

On the other hand, I'm really a C++ guy, and in that domain, I'd prefer your "const uint32_t" solution. It just feels more idiomatic.

Additionally and somewhat pedantically, I prefer naming conventions that make it clear when values are a constant, so I'd use "kHebrewCharMin" or something simliar.

Re:Vim 7.3.1000 by _pmf_ on Wednesday May 22, 2013 @02:01AM (#5749161)
One thing is that the compiler can warn about missing cases when using enums (GCC optionally does this); with defines, it's not clear that several values form a closed set.

The other thing is that function signatures can now show 'enum myenum e' instead of 'int v', which is much clearer.

Re:Vim 7.3.1000 by srl on Wednesday May 22, 2013 @08:17AM (#5750218)
> One thing is that the compiler can warn about missing cases when using enums (GCC optionally does this); with defines, it's not clear that several values form a closed set.

But here, the values /don't/ form a closed set, and using enums would imply that they do.

Re:Vim 7.3.1000 by zaphoyd on Tuesday May 21, 2013 @11:34PM (#5748714)
#define is a problem in general because the compiler doesn't understand as well what is happening because the substitutions take place outside of the language's type system. Extensive preprocessor use makes writing analysis tools, refactoring IDEs, and sane compiler errors much more complicated. Const in C doesn't behave similarly to #define so it isn't really a substitute.

Note: in C++, global/static const values do behave as compile time constant expressions and are an excellent tool for this purpose.

Re:Vim 7.3.1000 by redcircle on Tuesday May 21, 2013 @11:23PM (#5748681)
I don't feel that there is anything "wrong," just limiting, because the C preprocessor makes it harder to use tools that walk the abstract-syntax-tree while editing code (or to analyze code). LLVM-based tools are really nice. I don't care whether it is "const uint32_t ..." or enum, or anything else, as long as it is the C/C++/ObjC language.
Re:Vim 7.3.1000 by Macha on Tuesday May 21, 2013 @05:05PM (#5746831)
Given that it's in a regex source file, and the variable is named c, they're probably character codes for Unicode ranges.
Re:Vim 7.3.1000 by sltkr on Tuesday May 21, 2013 @05:19PM (#5746916)
Correct -- 0xfb20 through 0xfb4f are alternative glyphs for Hebrew characters. (I don't know what makes these so special that they need to be handled separately by the regexp processing code, though.)
Re:Vim 7.3.1000 by jlgreco on Tuesday May 21, 2013 @05:13PM (#5746873)
This might be a good case for unicode character literals. Code dealing with unicode can be a nightmare to work with, even if you already know what those numbers are (arguably as this bug demonstrates).
Re:Vim 7.3.1000 by sltkr on Tuesday May 21, 2013 @05:22PM (#5746934)
You realize you're talking about a codebase which still uses pre-standard parameter type declarations, right?
Re:Vim 7.3.1000 by jlgreco on Tuesday May 21, 2013 @05:24PM (#5746947)
Oh yes, Vim's code is anything but pleasant. I worked with it a decent amount several years ago when I was maintaining, for a short period of time, a patch that would add a terminal emulator to Vim windows.
Re:Vim 7.3.1000 by tsm on Wednesday May 22, 2013 @10:08AM (#5750900)
I was just searching for such a thing yesterday. Did the patch go anywhere?
Re:Vim 7.3.1000 by qu4z-2 on Thursday May 23, 2013 @01:18AM (#5755475)
Just curious what the advantages are of this versus C-z'ing back to the shell?

EDIT: Oh, I guess that doesn't work in gvim?

Re:Vim 7.3.1000 by tsm on Thursday May 23, 2013 @09:30AM (#5756694)
It's nice to see terminal output at the same time as you're editing. Right now I'm working on a Rails app, so it'd be great to see RSpec failures while fixing my code--currently I either alt-tab between terminals or use a second monitor.

Also, sometimes you don't want to wait for something. `bundle install` can take a good 30 seconds...I'd rather not watch that!

Re:Vim 7.3.1000 by qu4z-2 on Thursday May 23, 2013 @08:35PM (#5760518)
Thanks for the answer. Seems reasonable. Although at that point I'd somewhat suggest tmux :)
Re:Vim 7.3.1000 by Kurtz79 on Wednesday May 22, 2013 @03:33AM (#5749374)
Well, there is a place for "magic numbers" if considered within context.

Most people here would read 0xFF0000 and automatically think "red".

But I agree that in this case a define would have helped.