Pages

Showing posts with label programming language. Show all posts
Showing posts with label programming language. Show all posts

C++ Variadic Templates

 I've been using Visual Studio 2013 RC which supports C++ 11 variadic templates.

 Here are a few things I've noticed.

Good
  • Compile time reduced. Replacing my N duplicates of a template with a single instance means less work for the compiler
  • Less code. Is some cases *way* less code. This is great! Can replace manually duplicated templates with 1 instance, can also replace Boost Preprocessor generated templates with variadics
Bad
  • If you step into a variadic function in the debugger it does not always allow you to see what values were passed into the function.  I did see it work once, so perhaps it is just buggy/incomplete and the final release for VS 2013 will fix this.
  • The following code does not compile, to work around it, as far as I can tell, you must resort to C++ 03 code(boilerplate). You couldn't instantiate this type because it doesn't map to a struct/class, but it would make it easier to pass type information around.  


edit: Looks like there is a proposal to fix my last point- N3728

Microsoft's vector and alignment

Can't use Microsoft's implementation of vector with aligned data, all because of one line.

void resize(size_type _Newsize, _Ty _Val)

Change it to

void resize(size_type _Newsize, const _Ty& _Val)

And everything works.  But is hacking my STL files a good idea or should I use some other version of vector just for aligned data?

The standard was updated recently and indicates that 2nd version is now the correct way, so I believe this will be fixed eventually, probably the next edition of Visual C++, ah well-- I'll just hack it for now..

-edit(9/28/2013): this is no longer an issue in Visual Studio 2013, it works out of the box

Lua needs

 Lua is great, but it is missing a few things..

1.  continue                     -- although Lua 5.2 adds goto, which does allow you to simulate this, but I don't see myself using goto..
2.  no ++ or += etc.       -- don't know why this isn't supported, shouldn't be too hard to add with custom pre-compiler
3.  metaprogramming      --Lua just doesn't have any good support for this, have to manipulate strings to accomplish anything

Lisp

  Recently I've been teaching myself lisp-- so far it seems like a very creative language, which I like, as I view creativity as one of the most important skills for a programmer to have.

 There are like a million different versions of lisp it seems and no single standard implementation.

 And for whatever reason I decided to write yet another...

 My lisp compiles to Lua, I figured that LuaJIT2 is the fastest dynamic language VM around, so targeting it should allow my Lisp implementation to perform better than most. I had no experience with Lisp prior to this, but I certainly learned lisp fairly well while writing a compiler for it-- also improved my Lua.

 It is somewhat different from the lisp norm in that it does not use lists and cons cells, instead I use a Lua table in array form.  No named arguments either, although you can fake them just as you would in Lua.  I also use { to introduce raw Lua code, and } to return to Lisp.

 Still have to implement most of the library functions that come with most lisp implementations, and I'm sure I'll have to fix a few bugs in the compiler yet, but it is working, including support for macros.

 I also saw that the creator of Lisp, John McCarthy, died a few days ago:(