Programistok 2017: quick notes

Last Saturday I attended conference for programmers in my home town Białystok. Programistok“, because that how it’s called, is a one day event for about 400 people from different software development worlds: .NET, JavaScript, Python, Java and other. Here I would like to mention my top 3 presentations.
The first one from Andrzej Rusewicz was about productivity. He claimed that only delivering new features is productive. The rest like fixing bugs, refactoring has zero productivity. Another thought was about importance of the technical documentation. He said a very general idea, that “week of planning can protect us from months of zero productivity”. Can’t disagree, but of course it depends on project size, deadlines.
Next one from Mirosław Burnejko was kind of showtime. He was speaking with such tremendous confidence, that every meme on his slides makes everybody instantly laughing. Moreover he was smiling a lot and wore shirt with rolled up sleeves. He spoke about difference between AWS and Azure. The conclusion was that there is no real difference and the only reason to pick one of them is project technology. I appreciated the last thought that we should reuse existing services/tools instead of developing something from scratch. At the discussion panel he shares his productivity rule of “elimination-automation-delegation” of tasks.

And IMO the best presentation was delivered by Adam Sitnik. He talked about his story on contributing to open source. For instance, he told that merging Pull Request can took very long and you should prepare for tough questions from reviewers. He said that he never was below 5 fixes per PR or something like that. I experienced the same, so the next part of the story about what good happened to him was promising for me. The major benefits of contributing are learning the internal stuff (some advantage on debugging), collaborating with your programming idols/mentors. As a disadvantage he told that sitting overnight can damage health. Moreover it costs personal time, which is exceptionally valuable. His advice on what project to choose for contribution was the software you use everyday.

There was also great inspiring presentation from Sławek Sobótka, who I met at the after party and we talked about video games industry and Paleo diet, but I think it’s a material for another post 😉 As a last word, the conference was at very good level and I’m looking forward for the next year.

 

 

 

 


Slow Intellij 17.1 – Xmx for help

Yesterday I switched to 2017 version of Intellij from the good old 16.3. I didn’t read about all new features yet, but the first thing that hits me was new look of “Find in Path” window. It’s now completely redesigned and I couldn’t get used to it for the first couple hours. Now I don’t need to click to another tab to change search filters – it’s all in the results view already! Thanks JetBrains!

After running Intellij for the longer period of time without restarting, I noticed some lags. The Java editor was freezing for a second or two and it was really annoying! I couldn’t work 🙁 After looking for some “magic” tweaks in the internet, I found that maybe I should just double the Xmx setting. Original value was 750MB, so I have changed it to 1500MB. I enabled “Memory indicator” and after running some unit tests it exceeded the original value. Hope it helps in a long run!

Boiling frogs 2017 inspirations: teach (1)



It is longer than three weeks since I was attending that software craftsmanship conference in Wrocław. The seven-hour train journey was exhausting, but worth that amazing experience of meeting a lot of great people and learning something new about my job. Here I just want to share some thoughts with hope, that someone gets inspired.

Moore’s law of our times – Tomasz Kaczmarzyk (opening speak)

    • “The software craftsmanship manifest” was reminded. I think that every programmer aspiring to be a professional should recall it more often than on the conference. I would say at least once a month! The thing is to keep the focusing on “raising the bar”.
    • The next fun thing was a prediction of Uncle Bob, that “every 5 years the number of programmers doubles”. And here is my tweet about it:

    • There was nice explanation what “10x programmer” really means in the context of software craftsmanship: maybe 1 senior programmer cannot be as much productive as 10 junior programmers, but he can improve them by teaching and helping. So senior guys step up and don’t hesitate to be mentors! I believe that teaching is a natural way to become an expert.

 

[IntelliJ] Auto-filling Java call arguments like Eclipse did

After changing my IDE from Eclipse to IntelliJ, I suffered from lack of really helpful functionality of auto-completing method call arguments (topic on Stackoverflow).

The standard auto-completition wasn’t enough and “Ctrl+P” shortcut doesn’t satisfy me either.

Hopefully I found this issue: IDEABKL-5496 – Auto-filling the actual Java call arguments, where the last comment written just couple days ago has a great news for me!

Making long story short: some German developer made pretty cool plugin, that fix this problem!

https://github.com/kontext-e/AutoFillingCallArguments

Usage is very simple – you don’t need to know new shortcut, just press “Alt+Enter” and select “Fill …” from suggestions menu. It rocks!

[Guava] Preconditions

Preconditions should be ideal for situations, where there is no specific business exceptions for checking arguments and performance is not an issue.

JavaDoc:

https://google.github.io/guava/releases/19.0/api/docs/com/google/common/base/Preconditions.html

Example:

   /**
    * Returns the positive square root of the given value.
    *
    * @throws IllegalArgumentException if the value is negative
    */
   public static double sqrt(double value) {
     Preconditions.checkArgument(value >= 0.0, "negative value: %s", value);
     // calculate the square root
   }

 

Here is more about checking conditions:

https://github.com/google/guava/wiki/ConditionalFailuresExplained

Using Spock for testing code – getting started with syntax (1)

Getting started guide:
http://spockframework.org/spock/docs/1.0/spock_primer.html

Interesting things:

  • cool way to verify throwing exceptions:
    then: 
    EmptyStackException e = thrown() e.cause == null
  • instead of writing, “when-then”, just use “except”:
    expect:
    Math.max(1, 2) == 2
  • to parameterize test with different data, use “where” syntax:
    def "computing the maximum of two numbers"() {
    expect:
    Math.max(a, b) == c
    
    where:
    a << [5, 3]
    b << [1, 9]
    c << [5, 9]
    }
  • in helper method use “assert” keyword:
    assert pc.vendor == "Sunny"

Spring security handle AJAX XHR request for logout users and response 401 instead of 302

I found this article with filter implementation:

Spring Security part VI : Session Timeout handling for Ajax calls

However in comment someone point that we can simply extend “LoginUrlAuthenticationEntryPoint”.

My solution sets only status 401 and doesn’t write anything to response body:

	static class AjaxAwareLoginUrlAuthenticationEntryPoint
			extends LoginUrlAuthenticationEntryPoint {

		public AjaxAwareLoginUrlAuthenticationEntryPoint(String loginFormUrl) {
			super(loginFormUrl);
		}

		public void commence(HttpServletRequest request, HttpServletResponse response,
				AuthenticationException authException) throws IOException, ServletException {

			if (isAjaxRequest(request) && authException != null) {
				response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
				response.flushBuffer();
				return;
			}
			super.commence(request, response, authException);
		}

		private static boolean isAjaxRequest(HttpServletRequest request) {
			return "XMLHttpRequest".equalsIgnoreCase(request.getHeader("X-Requested-With"));
		}
	}

Workaround for “X-Forwarded” headers in Spring UriComponentsBuilder

When our application server user proxy, that doesn’t set “X-Forwarded” headers with original request port, then we can use some hack in our application. Just ignore port when it is equal 80 or 443, cause it is default. For example instead of "http://localhost:80/app", we will get "http://localhost/app". And "https://localhost:443/app" will output "https://localhost/app".

UriComponentsBuilder currentUrl = ServletUriComponentsBuilder
					.fromCurrentRequest();
int port = currentUrl.build().getPort();
currentUrl.port(port != 80 && port != 443 ? port : -1);
String currentUrlString = currentUrl.toUriString();

Inspired by Mat Banik strackoverflow answer – http://stackoverflow.com/a/5212336/5770135.