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.

 

Leave a Reply

Your email address will not be published. Required fields are marked *