Jump to page: 1 2
Thread overview
extending 'import' using 'with'
Apr 01, 2015
Mike James
Apr 01, 2015
w0rp
Apr 01, 2015
ketmar
Apr 01, 2015
w0rp
Apr 01, 2015
John Colvin
Apr 01, 2015
ketmar
Apr 01, 2015
Paulo Pinto
Apr 01, 2015
ketmar
Apr 01, 2015
Paulo Pinto
Apr 01, 2015
ketmar
Apr 01, 2015
Russel Winder
Apr 02, 2015
rumbu
Apr 01, 2015
Russel Winder
Apr 02, 2015
Dennis Ritchie
Apr 02, 2015
Jesse Phillips
Apr 02, 2015
weaselcat
Apr 03, 2015
Jacob Carlborg
Apr 01, 2015
Brad Anderson
Apr 01, 2015
Jacob Carlborg
April 01, 2015
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=-
April 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.
April 01, 2015
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... ;-)

April 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.
April 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.
April 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...

April 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.

April 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=-

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 :).
April 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
April 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.

« First   ‹ Prev
1 2