digitalmars.D - extending 'import' using 'with'
- Mike James (19/19) Apr 01 2015 Just a thought...
- w0rp (20/39) Apr 01 2015 string importSubmodules(string rootModuleName, string[]
- ketmar (7/7) Apr 01 2015 people with Java/C/C++/etc. background tend to forget about the power of...
- w0rp (4/17) Apr 01 2015 I tend to think mixins are used too much myself. They slow down
- John Colvin (3/6) Apr 01 2015 While true currently, there's a lot of opportunity to improve the
- ketmar (2/5) Apr 01 2015 but they are sooooo handy! i... can't... stop... need... more... mixins....
- Paulo Pinto (5/18) Apr 01 2015 Actually metaprogramming is how a lot of magic happens in Java
- ketmar (2/3) Apr 01 2015 without on-the-fly code generation that's a mockery.=
- Paulo Pinto (8/12) Apr 01 2015 You can generate code on the fly as well, that is a common trick
- ketmar (3/20) Apr 01 2015 as well as libjit and sparse for C, for example. but i will hardly name=...
- Russel Winder via Digitalmars-d (15/21) Apr 01 2015 You must not have done much JVM-based stuff recently, it's all about=20
- rumbu (13/17) Apr 02 2015 Metaprogramming in .net is done through T4 templates. This is a
- Russel Winder via Digitalmars-d (20/26) Apr 01 2015 Java metaprogramming is a real pain, so just use Groovy. (Though Java 8
- Dennis Ritchie (31/36) Apr 02 2015 C++ with boost:
- Andrei Alexandrescu (5/39) Apr 02 2015 Boost's preprocessor library is a scar on the landscape of C++. It has
- Jesse Phillips (3/7) Apr 02 2015 I think this falls into the same camp as nested imports. Why
- weaselcat (3/7) Apr 02 2015 no
- Jacob Carlborg (4/6) Apr 03 2015 Yeah, in a Java IDE it would automatically add the missing imports.
- Brad Anderson (4/23) Apr 01 2015 Weird timing. I just had this idea a couple nights ago and was
- Jacob Carlborg (6/22) Apr 01 2015 If you're really using DWT and this is not just an example, you can
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=-
Apr 01 2015
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.
Apr 01 2015
people with Java/C/C++/etc. background tend to forget about the power of=20 metaprogramming: they have no such tool at hand, so they don't even think=20 about it. three things that one need to become used of are UFCS (so std.algorighm=20 functions chains nicely), lambdas, and metaprogramming. but that has=20 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... ;-)=
Apr 01 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. 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.
Apr 01 2015
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.
Apr 01 2015
On Wed, 01 Apr 2015 15:23:58 +0000, 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 sooooo handy! i... can't... stop... need... more... mixins...=
Apr 01 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. 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.
Apr 01 2015
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.=
Apr 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: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.Actually metaprogramming is how a lot of magic happens in Java and .NET.without on-the-fly code generation that's a mockery.
Apr 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:as well as libjit and sparse for C, for example. but i will hardly name=20 that useful, let alone usable.=On Wed, 01 Apr 2015 16:16:58 +0000, Paulo Pinto wrote:=20 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. =20 Runtime reflection, attribute processing, AST manipulation and bytecode generation can help a lot in meta-programming. =20 It isn't as easy as D's mixins, but it gets the job done.Actually metaprogramming is how a lot of magic happens in Java and .NET.without on-the-fly code generation that's a mockery.
Apr 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: =20You must not have done much JVM-based stuff recently, it's all about=20 "on the fly" code generation. Not to mention all the "as we load the=20 code" code generation, aka AOT. Java 9 and Java 10 are going to be=20 quite fun. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winderActually metaprogramming is how a lot of magic happens in Java and=20 .NET.=20 without on-the-fly code generation that's a mockery.
Apr 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: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. debugging.Actually metaprogramming is how a lot of magic happens in Java and .NET.without on-the-fly code generation that's a mockery.
Apr 02 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=20 power of=20 metaprogramming: they have no such tool at hand, so they don't even=20 think=20 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=20 expressions.) C is a lost cause. C++ has a lot of template metaprogramming, but you have to be as good=20 as David Abrahams to be any good at it. Python (and Ruby, Lisp, Clojure, etc.) programmers have no problem=20 with this stuff. =20[=E2=80=A6]--=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 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
Apr 01 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
Apr 02 2015
On 4/2/15 2:52 AM, Dennis Ritchie wrote:On Wednesday, 1 April 2015 at 13:35:22 UTC, ketmar wrote: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. Andreipeople 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
Apr 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.
Apr 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.
Apr 02 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
Apr 03 2015
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 :).
Apr 01 2015
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
Apr 01 2015