Thursday, September 19, 2013

SevNTU Checkstyle version 1.9.0

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

About project and previous releases:
To Discuss:!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.
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.
       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.
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.
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(); 
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.
         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).
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.
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 - just press "t" and search appear.

Scala Lift steps how to compile and run


git clone
cd simply_lift/samples/http_rest
> update
> jetty-run

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

to do Project from scratch with all explanations:
just Rest example:

#udpate sbt-launch.jar from to latest version

# remove old file to activate changes
rm project/

#register eclipse plugin
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, ...)!topic/liftweb/503eibvCvV4

#examples of prod configurations

Scala vs Nodejs:

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!")

scala script.scala

2. Thought a Scala script

$ cat script.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 , 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:

Opposite results of performance:

Magic performance of Servlet Api 3.0 is due to "Java NIO (New I/O) API":

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 remote add bitbucket
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