>From SparkCodeStyleGuide
https://cwiki.apache.org/confluence/display/SPARK/Spark+Code+Style+Guide#SparkCodeStyleGuide-Imports
.

can find that import style as











*Always import packages using absolute paths (e.g. scala.util.Random)
instead of relative ones (e.g. util.Random). In addition, sort imports in
the following order: - java.* and javax.* - scala.* - Third-party libraries
(org.*, com.*, etc) - Project classes (org.apache.spark.*) *

Some of the Spark code also not follow the above order for import

Additionally it is better to include some additional style for import from
http://twitter.github.io/effectivescala/#Formatting-Imports

   - *Use braces when importing several names from a package import
   import org.apache.flume.source.avro.{AvroSourceProtocol, AvroFlumeEvent,
   Staus}*


   - *Use wildcards when more than six names are imported
                                  import org.apache.flume.source.avro._

    Don't apply this blindly: some packages export too many names*


   - *When using collections, qualify names by importing
   scala.collection.immutable and/or scala.collection.mutable

             Mutable and immutable collections have dual names.
                                       Qualifiying the names makes is obvious
   to the reader which variant is being used (e.g. "immutable.Map")*


   - *Do not use relative imports from other packages Avoid
                                    **import
   org.apache.flume.source.avro.AvroSourceProtocol          **import
AvroFlumeEvent

                                       **in favor of the unambiguous
                                                          *
   *import org.apache.flume.source.avro.AvroFlumeEvent*




* - Put imports at the top of the file The reader can refer to all imports
in one place. *

Post your thoughts.

Regards,
prabeesh

On Thu, Mar 13, 2014 at 1:49 PM, prabeesh k <prabsma...@gmail.com> wrote:

> example for unblocked import
>
>   import org.eclipse.paho.client.mqttv3.MqttClient
>   import org.eclipse.paho.client.mqttv3.MqttClientPersistence
>   import org.eclipse.paho.client.mqttv3.MqttException
>   import org.eclipse.paho.client.mqttv3.MqttMessage
>   import org.eclipse.paho.client.mqttv3.MqttTopic
>
> this can also be represented using blocked method as follows
>
>   import org.eclipse.paho.client.mqttv3.{MqttClient, MqttException,
> MqttMessage, MqttTopic, MqttClientPersistence}
>
>
>
>
> On Thu, Mar 13, 2014 at 1:39 PM, Prashant Sharma <scrapco...@gmail.com>wrote:
>
>>  What exactly do you mean by blocked and unblocked import ?
>>
>> Prashant Sharma
>>
>>
>> On Thu, Mar 13, 2014 at 1:32 PM, prabeesh k <prabsma...@gmail.com> wrote:
>>
>> > Hi All,
>> >
>> > We can import packages in Scala as blocked import and unblocked import.
>> >
>> > I think blocked import is better than other. This method helps to
>>  reduce
>> > LOC.
>> >
>> > But in Spark code using mixed type, It is better choose any of both.
>> >
>> > Please post your thoughts on the  Scala Style for import
>> >
>> > Regards,
>> > prabeesh
>> >
>>
>
>

Reply via email to