Re: extending 'import' using 'with'

2015-04-03 Thread Jacob Carlborg via Digitalmars-d

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


Re: extending 'import' using 'with'

2015-04-02 Thread weaselcat via Digitalmars-d

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.


Re: extending 'import' using 'with'

2015-04-02 Thread Dennis Ritchie via Digitalmars-d

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


Re: extending 'import' using 'with'

2015-04-02 Thread Jesse Phillips via Digitalmars-d

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.


Re: extending 'import' using 'with'

2015-04-02 Thread rumbu via Digitalmars-d

On Wednesday, 1 April 2015 at 19:04:43 UTC, ketmar wrote:

On Wed, 01 Apr 2015 16:16:58 +, 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.







Re: extending 'import' using 'with'

2015-04-02 Thread Andrei Alexandrescu via Digitalmars-d

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



extending 'import' using 'with'

2015-04-01 Thread Mike James via Digitalmars-d

Just a thought...

How about adding the keyword 'with' to 'import' to save on typing 
:-)


import  org.eclipse.swt.widgets.Canvas,
org.eclipse.swt.widgets.Composite,
org.eclipse.swt.events.DisposeListener,
org.eclipse.swt.events.DisposeEvent,
org.eclipse.swt.events.PaintListener,
org.eclipse.swt.events.PaintEvent;

import with (org.eclipse.swt) {
widgets.Canvas,
widgets.Composite,
events.DisposeListener,
events.DisposeEvent,
events.PaintListener,
events.PaintEvent;
}


Regards,

-=mike=-


Re: extending 'import' using 'with'

2015-04-01 Thread w0rp via Digitalmars-d

On Wednesday, 1 April 2015 at 10:21:46 UTC, Mike James wrote:

Just a thought...

How about adding the keyword 'with' to 'import' to save on 
typing :-)


import  org.eclipse.swt.widgets.Canvas,
org.eclipse.swt.widgets.Composite,
org.eclipse.swt.events.DisposeListener,
org.eclipse.swt.events.DisposeEvent,
org.eclipse.swt.events.PaintListener,
org.eclipse.swt.events.PaintEvent;

import with (org.eclipse.swt) {
widgets.Canvas,
widgets.Composite,
events.DisposeListener,
events.DisposeEvent,
events.PaintListener,
events.PaintEvent;
}


Regards,

-=mike=-


string importSubmodules(string rootModuleName, string[] 
subModuleNames) {

import std.algorithm;
import std.array;

string prefix = import  ~ rootModuleName ~ '.';

return subModuleNames.map!(name = prefix ~ name ~ ';').join
}

mixin(importSubmodules(org.eclipse.swt, [
widgets.Canvas,
widgets.Composite,
events.DisposeListener,
events.DisposeEvent,
events.PaintListener,
events.PaintEvent
]));

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.


Re: extending 'import' using 'with'

2015-04-01 Thread ketmar via Digitalmars-d
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.

three things that one need to become used of are UFCS (so std.algorighm 
functions chains nicely), lambdas, and metaprogramming. but that has 
downside: when you get used to those, you simply can't get back to Java/C/
C++/etc. anymore, they feels like something from the past age... ;-)

signature.asc
Description: PGP signature


Re: extending 'import' using 'with'

2015-04-01 Thread w0rp via Digitalmars-d

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.

three things that one need to become used of are UFCS (so 
std.algorighm
functions chains nicely), lambdas, and metaprogramming. but 
that has
downside: when you get used to those, you simply can't get back 
to Java/C/
C++/etc. anymore, they feels like something from the past 
age... ;-)


I tend to think mixins are used too much myself. They slow down 
compilation and inflate memory usage a lot. I always weigh the 
costs against the benefits.


Re: extending 'import' using 'with'

2015-04-01 Thread John Colvin via Digitalmars-d

On Wednesday, 1 April 2015 at 15:23:59 UTC, w0rp wrote:
I tend to think mixins are used too much myself. They slow down 
compilation and inflate memory usage a lot. I always weigh the 
costs against the benefits.


While true currently, there's a lot of opportunity to improve the 
situation.


Re: extending 'import' using 'with'

2015-04-01 Thread Paulo Pinto via Digitalmars-d

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.

three things that one need to become used of are UFCS (so 
std.algorighm
functions chains nicely), lambdas, and metaprogramming. but 
that has
downside: when you get used to those, you simply can't get back 
to Java/C/
C++/etc. anymore, they feels like something from the past 
age... ;-)


Actually metaprogramming is how a lot of magic happens in Java 
and .NET.


It just tends to be frowned up in many companies due to 
maintenance headhaches when one gets too clever.




Re: extending 'import' using 'with'

2015-04-01 Thread ketmar via Digitalmars-d
On Wed, 01 Apr 2015 15:23:58 +, w0rp wrote:

 I tend to think mixins are used too much myself. They slow down
 compilation and inflate memory usage a lot. I always weigh the costs
 against the benefits.

but they are so handy! i... can't... stop... need... more... mixins...

signature.asc
Description: PGP signature


Re: extending 'import' using 'with'

2015-04-01 Thread Brad Anderson via Digitalmars-d

On Wednesday, 1 April 2015 at 10:21:46 UTC, Mike James wrote:

Just a thought...

How about adding the keyword 'with' to 'import' to save on 
typing :-)


import  org.eclipse.swt.widgets.Canvas,
org.eclipse.swt.widgets.Composite,
org.eclipse.swt.events.DisposeListener,
org.eclipse.swt.events.DisposeEvent,
org.eclipse.swt.events.PaintListener,
org.eclipse.swt.events.PaintEvent;

import with (org.eclipse.swt) {
widgets.Canvas,
widgets.Composite,
events.DisposeListener,
events.DisposeEvent,
events.PaintListener,
events.PaintEvent;
}


Regards,

-=mike=-


Weird timing. I just had this idea a couple nights ago and was 
going to post about it here at some point. So I guess that means 
a +1 from me :).


Re: extending 'import' using 'with'

2015-04-01 Thread ketmar via Digitalmars-d
On Wed, 01 Apr 2015 19:36:53 +, Paulo Pinto wrote:

 On Wednesday, 1 April 2015 at 19:04:43 UTC, ketmar wrote:
 On Wed, 01 Apr 2015 16:16:58 +, 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.

signature.asc
Description: PGP signature


Re: extending 'import' using 'with'

2015-04-01 Thread Jacob Carlborg via Digitalmars-d

On 2015-04-01 12:21, Mike James wrote:

Just a thought...

How about adding the keyword 'with' to 'import' to save on typing :-)

import  org.eclipse.swt.widgets.Canvas,
 org.eclipse.swt.widgets.Composite,
 org.eclipse.swt.events.DisposeListener,
 org.eclipse.swt.events.DisposeEvent,
 org.eclipse.swt.events.PaintListener,
 org.eclipse.swt.events.PaintEvent;

import with (org.eclipse.swt) {
 widgets.Canvas,
 widgets.Composite,
 events.DisposeListener,
 events.DisposeEvent,
 events.PaintListener,
 events.PaintEvent;
}


If you're really using DWT and this is not just an example, you can 
import org.eclipse.swt.std to import the most common used modules or 
org.eclipse.swt.all to import all of them.


--
/Jacob Carlborg


Re: extending 'import' using 'with'

2015-04-01 Thread Paulo Pinto via Digitalmars-d

On Wednesday, 1 April 2015 at 19:04:43 UTC, ketmar wrote:

On Wed, 01 Apr 2015 16:16:58 +, 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.


Re: extending 'import' using 'with'

2015-04-01 Thread ketmar via Digitalmars-d
On Wed, 01 Apr 2015 16:16:58 +, 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.

signature.asc
Description: PGP signature


Re: extending 'import' using 'with'

2015-04-01 Thread Russel Winder via Digitalmars-d
On Wed, 2015-04-01 at 13:35 +, 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.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


signature.asc
Description: This is a digitally signed message part


Re: extending 'import' using 'with'

2015-04-01 Thread Russel Winder via Digitalmars-d
On Wed, 2015-04-01 at 19:04 +, ketmar via Digitalmars-d wrote:
 On Wed, 01 Apr 2015 16:16:58 +, 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.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


signature.asc
Description: This is a digitally signed message part