Thursday, September 19, 2013

SevNTU Checkstyle version 1.9.0

SevNTU Checkstyle Release 1.9.0 (18/September/2013):

Github: https://github.com/sevntu-checkstyle/sevntu.checkstyle
About project and previous releases: http://sevntu-checkstyle.github.io/sevntu.checkstyle/
To Discuss: https://groups.google.com/forum/?hl=en#!forum/sevntu-checkstyle

New in 1.9.0:

AvoidConstantAsFirstOperandInConditionCheck -  Avoid Constant As First Operand In Condition. If comparing values, C(C++) developers prefer to put the constant first in the equality check, to prevent situations of assignment rather than equality checking. But in Java, in IF condition it is impossible to use assignment, so that habit become unnecessary and do damage readability of code.
Example:
if (null == varialble)"
should be
if (varialble == null)"

Done by Sergey Burtsev.  More


EitherLogOrThrowException -  Either log the exception, or throw it, but never do both. Logging and throwing results in multiple log messages for a single problem in the code, and makes problems for the support engineer who is trying to dig through the logs. This is one of the most annoying error-handling antipatterns.
Example:
       catch (NoSuchMethodException e) {
          LOG.error("Blah", e);
          throw e;
      }
     

Done by Baratali Izmailov.  More


ForbidWildcardAsReturnTypeCheck -  Do not use wildcard types as return types. Rather than providing additional flexibility for your users, it would force them to use wildcard types in client code. Properly used, wildcard types are nearly invisible to users of a class. They cause methods to accept the parameters they should accept and reject those they should reject. If the user of a class has to think about wildcard types, there is probably something wrong with the class’s API.
Example:
public <T> List<? extends T> getValues()

Done by Baratali Izmailov.  More


NoNullForCollectionReturnCheck -  Check detect when method, that must return array or collection, return null value instead of empty collection or empty array.
Example:
public List<String> metValues() { return null; }

Done by Ilja Dubinin.  More


ConfusingConditionCheck -  This check prevents negation within an "if" expression if "else" is present.
For example, rephrase:
if (x != y) smth1(); else smth2(); 
as:
if (x == y) smth2(); else smth1(); 

Done by Vadim Panasiuk.  More

NoMainMethodInAbstractClassCheck -  Forbids main methods in abstract classes. Rationale: existance of 'main' method can mislead a developer to consider this class as a ready-to-use implementation.
Example:
         abstract class AbstractUiJob {
           ...  
             public static void main(String args[]){ ... } 
           ... 
         }
  

Done by Baratali Izmailov.  More

SimpleAccessorNameNotationCheck -  Check only direct fields and setter and getter. Options: 1) member prefix "m_" 2) check only simple getter/setter XXXType getXXXName(); void setXXXName(XXXType).
Example:
private String value; 
void setValue(String val) { this.value = val;}

Reimplemented and fixed by Ilja Dubinin.  More


AbbreviationAsWordInNameCheck -  problem detection of 2 char abbreviation with length limit 1 was fixed.
Example:
int scaleX;

Done by Baratali Izmailov.  More

Thursday, September 12, 2013

Github need to have search of files feature in repo

I will be lovely if Github create search in repo at least by file name (with support of matching by Camel case), it will be very useful during sources investigation. Developers always search for files, and gihub is not just a web hosting - it is online editor, and allow contribution to project without clone to local PC.

This feature exists - https://github.com/blog/793-introducing-the-file-finder just press "t" and search appear.

Scala Lift steps how to compile and run


Lift: http://liftweb.net/download
Examples: https://github.com/dpp/simply_lift

git clone https://github.com/dpp/simply_lift
cd simply_lift/samples/http_rest
./sbt
> update
> jetty-run

But this project use old version of scala and lift and sbt

to do Project from scratch with all explanations: http://cookbook.liftweb.net/#InstallAndRunning
just Rest example: http://simply.liftweb.net/index-5.3.html#toc-Section-5.3

Experiments:
#udpate sbt-launch.jar from http://www.scala-sbt.org/release/docs/Getting-Started/Setup.html to latest version

# remove old file to activate changes
rm project/build.properties

#register eclipse plugin https://github.com/typesafehub/sbteclipse/
echo "addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.3.0")" > simply_lift/samples/http_rest/project/plugins.sbt


Deploy (jetty, tomact ):
#create a war in target folder
sbt package

#deploy war to Java application server (jetty, tomcat, ...)
https://groups.google.com/forum/#!topic/liftweb/503eibvCvV4

#examples of prod configurations
https://www.assembla.com/spaces/liftweb/wiki/Deployment

Scala vs Nodejs: http://blog.nelsonsilva.eu/2010/12/14/go-vs-scala-vs-nodejs/index.html#disqus_thread

Monday, September 9, 2013

Scala meetup at Netflix office 2013-09-09

How to run scala as script

1. Through interpreter
$ cat script.scala
println("Hello, World!")

Run:
scala script.scala

2. Thought a Scala script

$ cat script.scala
#!/usr/bin/scala!#
println("Hello, World!")

Run as:
$ ./script.scala

3. Compile and then run compiled class
, source.

$ cat script.scala
object Greeting {
    def main(args: Array[String]) = println("Hello world!")
}

Run as:
$ scalac script.scala
$ scala Greeting


Happy scripting!

Friday, September 6, 2013

Comparison web framework for rest api on scala

I did search for the best way to implement simple RESTfull Api service on JVM based technologies (not a node.js and "go" lang). Scala come up as good alternative, additional search shown a Lift framework that looks like popular between Scala community and a lot of posts recommend to do rest api on it, but ...

I met Alexy Khrabrov on one of Scala meetup, and he recommended me to take a look at project https://github.com/Versal/scamper , that do show comparison of RESTful libraries and frameworks, and results are pretty interesting and shown that Lift is not ideal for performance demanding web services.

Just Java Servlet Api 3.0 show petty good performance - that make me think "Should I stay with Java? What can I benefit from Scala ?" :).

Useful stack-overflow discussions: discussion1, discussion2.

My final decision for deep investigation and try is spay: http://spray.io/blog/2013-05-24-benchmarking-spray/

Opposite results of performance: http://irregularexpression.blogspot.com/2012/02/expressjsnodejs-vs-sprayakka-restful.html?m=1

Magic performance of Servlet Api 3.0 is due to "Java NIO (New I/O) API": http://www.onjava.com/lpt/a/5127

Sync local git repository with remotes github and bitbucket

It is common case when you need sync sources between few remote repositories of git, mostly one of them is backup mirror or you have two communities and do not want to bother them what is better github or bitbucket.

#recheck what remotes you have already
git remote

# add link to github and bitbucket remote repo
git remote add github git@hithub.com:my-repo-name.git
git remote add bitbucket https://bitbucket.org/user/my-repo-name
git push -u github master
git push -u bitbucket master

#Somebody sent you fixes to bitbucket rep - pull it from bitbucket and push github
git pull bitbucket
git push github