April 01, 2015
On Wednesday, 1 April 2015 at 19:04:43 UTC, ketmar wrote:
> On Wed, 01 Apr 2015 16:16:58 +0000, Paulo Pinto wrote:
>
>> Actually metaprogramming is how a lot of magic happens in Java and .NET.
>
> without on-the-fly code generation that's a mockery.

You can generate code on the fly as well, that is a common trick to create, for example, optimized ORMs, regular expression engines or image processing algorithms that are then compiled to native code with the JIT.

Runtime reflection, attribute processing, AST manipulation and bytecode generation can help a lot in meta-programming.

It isn't as easy as D's mixins, but it gets the job done.
April 01, 2015
On Wed, 01 Apr 2015 19:36:53 +0000, Paulo Pinto wrote:

> On Wednesday, 1 April 2015 at 19:04:43 UTC, ketmar wrote:
>> On Wed, 01 Apr 2015 16:16:58 +0000, Paulo Pinto wrote:
>>
>>> Actually metaprogramming is how a lot of magic happens in Java and .NET.
>>
>> without on-the-fly code generation that's a mockery.
> 
> You can generate code on the fly as well, that is a common trick to create, for example, optimized ORMs, regular expression engines or image processing algorithms that are then compiled to native code with the JIT.
> 
> Runtime reflection, attribute processing, AST manipulation and bytecode generation can help a lot in meta-programming.
> 
> It isn't as easy as D's mixins, but it gets the job done.

as well as libjit and sparse for C, for example. but i will hardly name that useful, let alone usable.

April 01, 2015
On Wed, 2015-04-01 at 13:35 +0000, ketmar via Digitalmars-d wrote:
> people with Java/C/C++/etc. background tend to forget about the power of metaprogramming: they have no such tool at hand, so they don't even think about it.

Java metaprogramming is a real pain, so just use Groovy. (Though Java 8 at least has higher-order functions. method references and lambda expressions.)

C is a lost cause.

C++ has a lot of template metaprogramming, but you have to be as good as David Abrahams to be any good at it.

Python (and Ruby, Lisp, Clojure, etc.) programmers have no problem
with this stuff.

> […]
-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


April 01, 2015
On Wed, 2015-04-01 at 19:04 +0000, ketmar via Digitalmars-d wrote:
> On Wed, 01 Apr 2015 16:16:58 +0000, Paulo Pinto wrote:
> 
> > Actually metaprogramming is how a lot of magic happens in Java and .NET.
> 
> without on-the-fly code generation that's a mockery.

You must not have done much JVM-based stuff recently, it's all about "on the fly" code generation. Not to mention all the "as we load the code" code generation, aka AOT. Java 9 and Java 10 are going to be quite fun.

-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


April 02, 2015
On Wednesday, 1 April 2015 at 13:35:22 UTC, ketmar wrote:
> people with Java/C/C++/etc. background tend to forget about the power of
> metaprogramming: they have no such tool at hand, so they don't even think
> about it.

C++ with boost:

-----
#include <iostream>

#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/seq/for_each.hpp>

namespace a { namespace b {
    namespace x {
      int test1 = 1;
    }
    namespace y {
      int test2 = 2;
    }
    namespace z {
      int test3 = 3;
    }
  }
}

#define USE_NAMESPACES_IMPL( r, root, name ) \
  using namespace root :: name;

#define USE_NAMESPACES( root, names ) \
  BOOST_PP_SEQ_FOR_EACH( USE_NAMESPACES_IMPL, root, names )

USE_NAMESPACES( a::b, (x)(y)(z) )

int main() {

  std::cout << test1 << '\n'; // 1
  std::cout << test2 << '\n'; // 2
  std::cout << test3 << '\n'; // 3

  return 0;
}
-----
http://ideone.com/LncucP
April 02, 2015
On 4/2/15 2:52 AM, Dennis Ritchie wrote:
> On Wednesday, 1 April 2015 at 13:35:22 UTC, ketmar wrote:
>> people with Java/C/C++/etc. background tend to forget about the power of
>> metaprogramming: they have no such tool at hand, so they don't even think
>> about it.
>
> C++ with boost:
>
> -----
> #include <iostream>
>
> #include <boost/preprocessor/cat.hpp>
> #include <boost/preprocessor/seq/for_each.hpp>
>
> namespace a { namespace b {
>      namespace x {
>        int test1 = 1;
>      }
>      namespace y {
>        int test2 = 2;
>      }
>      namespace z {
>        int test3 = 3;
>      }
>    }
> }
>
> #define USE_NAMESPACES_IMPL( r, root, name ) \
>    using namespace root :: name;
>
> #define USE_NAMESPACES( root, names ) \
>    BOOST_PP_SEQ_FOR_EACH( USE_NAMESPACES_IMPL, root, names )
>
> USE_NAMESPACES( a::b, (x)(y)(z) )
>
> int main() {
>
>    std::cout << test1 << '\n'; // 1
>    std::cout << test2 << '\n'; // 2
>    std::cout << test3 << '\n'; // 3
>
>    return 0;
> }
> -----
> http://ideone.com/LncucP

Boost's preprocessor library is a scar on the landscape of C++. It has wrecked such disasters on compilation times at work, that we're considering disallowing it with a lint rule.

Andrei

April 02, 2015
On Wednesday, 1 April 2015 at 19:04:43 UTC, ketmar wrote:
> On Wed, 01 Apr 2015 16:16:58 +0000, Paulo Pinto wrote:
>
>> Actually metaprogramming is how a lot of magic happens in Java and .NET.
>
> without on-the-fly code generation that's a mockery.

Metaprogramming in .net is done through T4 templates. This is a Visual Studio feature, not a language feature.

There are two types of T4 templates:
- text templates - similar to mixins in D, you create a .tt file and each time you save it, a counterpart source file (even a .d source file) is created;
- runtime text templates - code is generated and compiled at runtime on the fly.

That's how most of the Visual Studio code designers and generators work.

Template language can be C# or VB and T4 templates support debugging.




April 02, 2015
On Wednesday, 1 April 2015 at 12:09:25 UTC, w0rp wrote:
> Of course, why be clever here at all and do such things? It's an editor problem. Write the full import lines out, and if you hate typing out the path each time, use tricks in your editor to make that easier, or use an IDE.

I think this falls into the same camp as nested imports. Why doesn't it already work? Seems like an arbitrary limitation to me.
April 02, 2015
On Wednesday, 1 April 2015 at 12:09:25 UTC, w0rp wrote:
>
> Of course, why be clever here at all and do such things? It's an editor problem. Write the full import lines out, and if you hate typing out the path each time, use tricks in your editor to make that easier, or use an IDE.

no
this is the reason java is unusable without an IDE.
April 03, 2015
On 2015-04-02 21:21, weaselcat wrote:

> no
> this is the reason java is unusable without an IDE.

Yeah, in a Java IDE it would automatically add the missing imports.

-- 
/Jacob Carlborg
1 2
Next ›   Last »