I have to teach a senior programmer Java?

We’ve gotten a new hire today

We hired a senior programmer to replace a employee who resigned last month, it turned out he does not have the tech profile we need. We focus heavily on Java but this guy is a Web Developer according to himself. My boss request me to take care of him and I wonder how? I introduced him to our colleagues and have lunch with them together, in the mean while I tried to understand his profile because my boss didn’t invite me to the interview of this senior programmer.

He is a web developer and has a question mark on his face

I asked him for a brief summary of his technology profile and he replied: html/css/javascript/”Experienced with Java” ( whatever that means.. ) . I sat next to him and want to have a rough idea of his level. I asked him about Eclipse and Java, he keep saying he only has experience with Java in the university and he graduated like 3 years ago, since then he develop website and I don’t know how much he could do.

It’s beyond my imagination

I have never expected my boss to hire a guy who does not have working experience with Java and I wonder whether I have to teach him, because we use Java here and not javascript, Verdammt! Do I have to teach him what is MVC and data modeling? I am thinking whether I should give him an assignment which require him to write some looping in order to check that he really knows programming.

I have stomach ache in the afternoon because of my increased responsibility. I am not in a role with require management of staff, I am not saying I can interact with human, actually I chat with my colleague regularly about daily stuff, but I am not teaching them about programming.

 

If I have a choice

I would fire him because it is obviously a mistake in recruitment. It’s better to deal with it earlier than later. But I am not in the position to suggest such thing. I have reflected this issue with my boss and he would decide.

I hate the guys who created Python 3, now I want Java again

There has been several months of difficult time and I haven’t blogged. I did some development but there is no point talking about it because I want to start from scratch with Java.

I hate Python 3 and everything that come with it

I am the average Joe developer and certainly I am not those who lead technology advance. I hate the guys who created Python 3 and decided it should be incompatible with everything of Python 2 because it leads to so many buys and difficulties in development. They said we should ditch Python 2 but most Linux distribution come preinstalled with Python 2 as “the Python”. Also python has a Pip which also comes with Pip 2 and Pip 3, with Pip 2 being the default one.

Now I just want to write program, do development instead of messing with system setting issue. Today I wasted at least one hour configuring PyCharm Professional with virtualenv. I don’t know what is the problem and I don’t want to waste time on it.

It could be the package “mecab-python3” used some default setting of Python 2 and crashed? I don’t know. I have already configured the system with default Python 3 and Pip 3 but it still happens.

I installed PyCharm Professional ( Trial ) because I don’t want to fiddle with command line anymore

During all the time with this “project”, I code with command line “Flask” and notepad++. But I fed up with it because every time I make a code change, I have to kill the running Flask server with Ctrl+Z and run “Python app.py” again. Ideally, I wish there is an IDE environment which behave like Eclipse of Java. Eclipse support Tomcat and I could bundle Spring project with it and the configuration is so simple. I just press the green arrow button “Run”. Coding, Testing in the same windows.

Now this command line won’t even work

Because I haven’t touch the code for a while, somehow it didn’t work as before. Did I make a fresh install of my PC? I don’t remember it. It should have work as expected but it does not work.

There should be a way to do development so that you close the IDE today, so it still works 100 days later after you click the funny icon which launch the IDE.

I made a simple program and at least 15 actual person said thank you

It’s been a while since the last post because of life and my project has been on a pause. But this post is not about the project but a simple program I made for my own good.

I am learning German language and one of the greatest difficulties is that German verb has conjugation ( verbs changes its’ form under different tenses ) and I think it would be very helpful to have a full list of all six conjugations of some common verbs. I have a list of 100 most important verbs which I got from internet ( there are plenty of those list ) and an online conjugator service ( http://conjugator.reverso.net/ ). You could enter the infinitive form of a verb in the website and it returns all forms of it.

Screenshot of Reverso Conjugation

However, I don’t want to lookup every words because that require 100 and more lookups. I asked about alternative to it online at Reddit subreddit /r/German but people suggest Duolingo and Memrise, which I don’t like. I much prefer a full list in an excel format so I could browse at it whenever I need. But obviously the website would not provide this kind of list, because otherwise no one would need their service anymore once we get the list.

In short, I made the program and ran it with 100 most important German verbs and use Selenium to look up the conjugations for me on Reverso Conjugation. I post the result excel on reddit, and I received 233 upvotes ( Greatest amount of upvote I have received in Reddit ) and received 15 actual “Thank you” in comment section.

Screenshot of my post at Reddit

To be honest, I know I am not the brilliant kind of developer, and probably are mediocre but at least I know how to program and those program are much more than simple Hello World. I usually refuse to work on project unless I am motivated ( either by money, aka in Office, or I need that program ). I am keen on automation, scripting, web scraping. Full stack programming is not my strength and I don’t familiar with the latest technology, but I produce VALUE.

The excel I made with a Java program. It is beautiful and very useful.

More on the Java program it self. It is a normal java program with the help of Selenium and JSoup. I have to use Selenium because the website Reverso Conjugation is not a static website and it generate its content dynamically with javascript. So I have to use Selenium to pretend that an actual person use a real browser to lookup thing, and copy the source code of generated webpage. After I get the source code, I break it apart with JSoup and look for what I need. I know for each tense, the content are being stored under an html tag with class “.blue-box-wrap”, so I take everything from there.

“Chrome is being controlled by automated test software.”That’s it for today!

Project process – Things got into shape, and I finally know to appreciate REST APIs

Language Translator from IBM Cloud

Language Translator

The project has finally gotten into shape! Last time I wrote that I wanted to include a translation by google translate in my web application, it turned out Google charge quite a bit for the Google Translate API, so I turned for other free service and found Language Translator from IBM Cloud. It allows free translator of 1,000,000 characters per month and is enough for development purpose.

latest screenshot of the web application

Product Layout

Now this web application is divided into four sections ( excluding the button ):

Left-Top section: Source text provided by user

Middle Top section: A tokenized version of the source text by part-of-speech. Access by a REST API written with Flask.

Rightmost section: A list of words translated by a free Japanese-English dictionary JMdict.

Lower section: A large textarea which hold the translation result by IBM Cloud Language Translator.

Product Functions

  • Tokenize Japanese text according to its part-of-speech, which are estimate by MeCab
  • If mouse over a tokenized word, the tooltip would show part-of-speech
  • Provide dictionary result of the words
  • Provide real translation by translation service

 

Now I am not going to make it prettier just for the sake of it. I have to ready the production environment and how to ship it. Also I have to wrap my REST API with HTTPs and make sure no one could access it except my server.

To be honest, the Language Translator API sucks

IBM Cloud provided four ways to access its Language Translator, they are: curl, Node, Java and Python. Ideally I would have chosen the Python way to access it. However, it requires Visual C++ Framework 14.0 and I would have to download Gigabytes of data just to install the Visual Studio Community 2017 which contains Visual C++ compiler. To be honest, I hate Microsoft stuff with passion because of the horrible experience with coding Visual Basic.

Since it is a Python project, I don’t want to mix it with Java or NodeJS. The last option is an ugly Curl API like this:

curl --user apikey:{apikey_value} --request POST --header "Content-Type: application/json" --data "{\"text\": [\"Hello, world!\", \"How are you?\"], \"model_id\":\"en-es\"}" https://gateway.watsonplatform.net/language-translator/api/v3/translate?version=2018-05-01

It has to use slashes ( ‘\’ ) to escape the double quotes ( ” ) in order to send a JSON over curl data. And in order to use this in a Python Program, not only do I have to Use Python Subprocess to call external program “curl”, I have to escape the slashes one more time with a double slash ( \\\ )

“curl –user apikey:XXXXXXXXXXXXXXXXXXXXXXXXXXXX –request POST –header \”Content-Type: application/json; charset=UTF-8\” –data \”{\\\”text\\\”:[\\\”” + text +”\\\”],\\\”model_id\\\”:\\\”ja-en\\\”}\” \”https://gateway-syd.watsonplatform.net/language-translator/api/v3/translate?version=2018-05-01\””

 

Man this is ugly, but it comes with free service. Now I finally understand why REST API is a thing. You don’t need to install anything, you just send a request over HTTP and it magically return something to you!

A small step for a man – overcoming Java Generics

Source Code of ArrayList.java

I did it finally. There was one part of Java in which I had never get over and that was Generics, the major feature of Java 5. The syntax was complicated and hard to understand the bunch of mysterious keyword E K N T V S ?. There is total 23 pages in the original Java tutorial of Generics and it proves that it is complicated.

I hate the long and mind boggling tutorial with a lot of jargons ( type parameter, parameterized type, upper bound lower bound, wildcard, type erasure, etc ), but I love ArrayList, which is a generic class. I used it almost everyday in place of the simple Array. I like the many convenient methods provided by ArrayList, such as add(int index,
E element)
,addAll(Collection<? extends E> c)contains(Object o)get(int index),indexOf(Object o),isEmpty(), remove(int index),removeAll(Collection<?> c)sort(Comparator<? super E> c)

I ran across a blog article titled ” Destroying the most common fear – “Generics?! It’s too hard for me!”” on Linkedin. The author tried to simplified the tutorial although it didn’t help much because of the nature of Generics. I read on anyway and write his example in Eclipse and see which works.

Actually I always know the rough idea of Generics, because I know I could put anything in an ArrayList, when I declare them with the correct type like ArrayList<String>, ArrayList<Integer>. It’s the same class and it achieves different purpose because of polymorphism.

Made up class called Bobby

Off my head there are few things I could do with Generics maybe container. There is a box and I don’t know what would be put inside, but I only want to know how many are in there, how do I take one item out, actually I don’t even need to know what would be put inside. That’s basically Java Collection! But Java has already done that.

Java 8 API documentation

Let’s call it a day.

Project progress and something I like/hate of ReactJS

Actually I have finished the backend API for a while. Instead of using Django, I chose Flask because I don’t need the model in Django. There are so much steps you need to do a simple thing in Django. With Flask, I write an api and it’s done. Of course Django is more mature and has more features but I don’t need them now.

The problem is frontend because I am not a frontend developer, to say it precisely, I don’t do much html/css/javascript stuff. Anyway, I don’t want to use AngularJS ( which have experience with ) because it’s a full blown framework with its own MVC paradigm. I just want a simple web page which show two textbox and a button. So I chose React and had to go through the tutorial.

For some reason, I kinda hate it. I like it for the component idea and I don’t have clutter up my html with jsp/php whatever, I just put everything inside a .js file. However, during the tutorial, I found something which made me nausea.

Function and ECMA6 class

First of all, it’s the choice between using a function or a ECMA6 class to describe a component. In the official documentation , there are many examples of function AND ECMA6 class appear together and both of them are Component of React. For instance:

function BoilingVerdict(props) {
  if (props.celsius >= 100) {
    return <p>The water would boil.</p>;
  }
  return <p>The water would not boil.</p>;
}
class Calculator extends React.Component {
  constructor(props) {
    super(props);
    this.handleChange = this.handleChange.bind(this);
    this.state = {temperature: ''};
  }

  handleChange(e) {
    this.setState({temperature: e.target.value});
  }

  render() {
    const temperature = this.state.temperature;
    return (
      <fieldset>
        <legend>Enter temperature in Celsius:</legend>
        <input
          value={temperature}
          onChange={this.handleChange} />
        <BoilingVerdict
          celsius={parseFloat(temperature)} />
      </fieldset>
    );
  }
}

It make sense with the class way to make a Component. It doesn’t make much sense for me with the Functional way. In my paradigm, I believe there should be only ONE way to do the same thing. It is confusing to see a function there but it’s not a real function. Yes it does return something but it serve the purpose like a Class. I think they should change all of them to Class instead of using function for Component.

States and Props

Second, there are difference between state and props. It’s confusing in the example because they introduce state first with an working example, and later told me to put it away and replace it with props. In additon, they were used in the same way: “this.state.someThing” and “this.props.someThing” and I think it’s confusing for beginner. I assume it’s like fields of super class in Java but it has extra work to pass the state of super class to subclass. We could do it cleaner with Java:

package me.rayentwickler.main;

public class TestSuperClass {
private String generalPropertyA;

public TestSuperClass(String generalPropertyA){
this.generalPropertyA = generalPropertyA;
}
public String getGeneralPropertyA() {
return generalPropertyA;
}

public void setGeneralPropertyA(String generalPropertyA) {
this.generalPropertyA = generalPropertyA;
}

}

package me.rayentwickler.main;

public class TestSubClass extends TestSuperClass {

    public TestSubClass(String generalPropertyA){
super(generalPropertyA);
}
public static void main(String[] args){
TestSubClass myInstance = new TestSubClass(“ABC”);
System.out.println(myInstance.getGeneralPropertyA());
}
}

In Java, if two class have ancestor/child relationship, I don’t have to tell Java that what kind of fields does the ancestor have. But it ReactJS, it seems I have to do a lot of boilerplate code!

 

Props are Read-Only, but we could change it by setState()

React said it provide a one-way data flow to make the world safer, so props are read-only. However, because the mother component still to access all the states of its children, we need to “Lift the state up” so that every state are stored in the top most Component and the state are passed down to children like a waterfall ( The real nature waterfall, not SDLC ). However, usually we want to accept user input and change the state which is props in this case, but props are read-only! What now? Well, ReactJS provided a way to call upper level component’s function, and in the function it called setState()! Since state could be modified, and after each update, render() would be call and states are passed to children again with new values. Seriously, it sounds like a loophole in its paradigm.

Coding Horror – C code in disguise of Java

There is huge demand for software developers in the market but there are not enough candidates which fits the requirement of company. Thus, on and off there would be some developers who has coding issue, were hired. Today I would share some bizarre code I have seen in workplace.

Let’s start with conclusion, “He/She is a C developer instead of a Java developer. He/She is writing C code while pretending it is Java.”

The case is this: we need to generate several reports with data from database. Let’ say there are 10 reports. Here is some strange code I’ve seen, it is not the real code, I have change it and omitted some detail which is related to company’s business:

private final static String[][] titles = { {“Column A1”, “Column B1”}, {“Column A2”, “Column B2”}, {“Column A3”, “Column B3”} ,{“Column A4”, “Column B4”}, {“Column A5”, “Column B5”}, {“Column A6”, “Column B6”}, {“Column A7”, “Column B7”}, {“Column A8”, “Column B8”}, {“Column A9”, “Column B9”}, {“Column A10”, “Column B10”}};

Who use two-dimensional array for String? In this case, the column headers for each reports are not related to each other so they should not be in an array. An array is used for data which has order relationship, of the same type. This developer just use two-dimensional array for convenience. Also, there configuration stuff should be put in a configuration file so that later when we change the column header, we don’t have to compile the code again.

BufferedWriter[] bfwList = prepareBufferedWriter();

Come one, what is this? Same argument as above.

 

genReport1(bwList[0], dao);
genReport2(bwList[1], dao);







genReport10(bwList[9], dao);

This part is where the real work happens. It’s pain to see he/she passed a BufferedWriter to a method. It’s illogical and not necessary. To be honest, I won’t declare a BufferedWriter outside of the method. I would prefer this:

public void genReport( String filename );

The BufferedWriter I would create INSIDE the method with the provided filename ( with actual file path ). I don’t pass a DAO ( data access object ) around. The DAO should be a class member of the service class in which this method belongs to so that it already has access to the DAO.

In conclusion, it is not object oriented programming, it is a C procedural programming disguised in Java.

 

My sentiments over Java and Python – Part 1

Photo by Mike Kenneally on Unsplash

 

I want to write about the decision between using Java and Python. Although I have more experience with Java, I chose Python, nonetheless, it wasn’t a resounding victory of Python over Java. Let’s think about the pros and cons of them.

Here is the technology stack of major tech companies according to stackshare:

Google: Python, Java, Go, C++, Dart
Apple: Swift, Objective-C
Microsoft: C#, .NET, Visual Basic
Intel: Java
Facebook: PHP, React(Javascript)
Oracle: Java

Out of six major tech companies, three of them use Java while one uses Python. Java was owned by Oracle and the language itself has been under heavy testing by the best developers around the world. There are billions of application made with Java. There is a saying that “Java is the new COBOL”, meaning that it’s to big to fail and everyone is depending on it.

Regarding the Java language itself I don’t have much complains, although the syntax are known as verbose. I would imaging it as a big heavy hammer which could smash whatever it want, however, only the brightest developers could maneuver it good enough to do that. It’s very powerful if given enough cpu/gpu power with its concurrency capabilities.

However, I hate Java’s framework. As mentioned earlier, I am a kind of developer who use library instead of writing from scratch. And there is a problem because there are too many different way to accomplish the same thing, with mind numbing XML configuration. Later they abandoned XML and went for annotation. The annotation came like magicians and did things without telling us the logic. For example, here is a snippet of spring configuration for security:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/", "/home").permitAll()
                .anyRequest().authenticated()
                .and()
            .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
            .logout()
                .permitAll();
    }

    @Bean
    @Override
    public UserDetailsService userDetailsService() {
        UserDetails user =
             User.withDefaultPasswordEncoder()
                .username("user")
                .password("password")
                .roles("USER")
                .build();

        return new InMemoryUserDetailsManager(user);
    }
}

Nothing could be more vague each the phrase “enable web security”. What? How? I see some code relating to authorization with weird syntax. According to the API documentation:

Add this annotation to an @Configuration class to have the Spring Security configuration defined in any WebSecurityConfigurer or more likely by extending the WebSecurityConfigurerAdapter base class and overriding individual methods:

I know every word of this sentence, but when they combined, I don’t know what it is talking about. What is WebSecurityConfigurer? And what is WebSecurityConfigurerAdapter?

I had some experience with using Spring 3 and I only used it for Dependency Injection, Inversion of Control, etc. I really appreciate Spring for eliminating the boilerplate code for JDBC. But then again here came Spring Boot, and everyone is advised to use Spring Boot instead of normal Spring. Here we go:

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
        return args -> {

            System.out.println("Let's inspect the beans provided by Spring Boot:");

            String[] beanNames = ctx.getBeanDefinitionNames();
            Arrays.sort(beanNames);
            for (String beanName : beanNames) {
                System.out.println(beanName);
            }

        };
    }

}

It didn’t look like what I was used to. Does it mean I have to abandon all of my work? According to the folks on internet, it seems Spring was too complicated so they created a framework FOR a framework!

Here I end all of my rants over Java, and if I have to, I would use J2EE over Spring, but I would like to avoid it all together.

 

It gets too long and I would continue the Python part next time.