Let’s imagine we have an e-commerce system. It tracks price values and discount values for items. Example records are

{item_id: item1, price: 1000, discount: 10},
{item_id: item2, price: 2000, discount: 30}, …

Now, you have to update the records. We will receive new price value for specific item_id. For example,

{item_id: item1, price: 860}

is an event you have to process. Thing is we have to update discount values upon the price change while keeping the original discount percentage.

For example, we’ll update discount value from 10 to 9 for the above price updates according to calculation like (old_discount/old_price) *…

It’s quite common operation to convert a list into a map with particular key. For example, convert a list

to a map

We have 2 ways to do this in Java. One way is good-old days for-loop.

Alternative is to use stream() interface like

Then, what’s the difference between the former and the latter ?

O.K. An example below illustrate the answer.

Yes, duplicate key. The former implementation of loop will override the values on the duplicated key, while the latter implementation will throw java.lang.IllegalStateException: Duplicate key exception.

There is a related question on stackoverflow. Looks like people tends to overlook the duplicate key case (sorry, that’s me honestly.). I feel like this is another benefit to use stream() interface as it reminds us of these corner cases.

Loading environmental values into class is almost always necessary for commercial applications, e.g. loading stage configuration of delivery pipeline. With DI library such as Guice, loading environmental variables can be hidden inside the module class.

Let’s see the simplest example. We have 2 classes both of which just load the environmental values and return the message string with it. There are slight difference in how they load the value.

  • ClassWithEnv: Loading environmental variables directly with System.getenv()
  • ClassWithInjectedEnv: Using Guice to load the value of the environmental variables.

Code snippet.

Which implementation is better ? I think most people agree…

How do you manage test data in your unit tests or automated API tests ?

If you tests API with large input data, for example JSON, it eventually gets harder to manage test data as you add more test cases. Imagine, what happens when you have 1000+ test cases !

I think we have 2 common strategies for the test data management.

  1. Not share test data across test cases. It’s pretty simple strategy. Each test case has full set of test data independently. They may be managed in the separated files. Advantage of this approach is that there is a…


When I learned algorithms for strongly connected components (SCC) in the university, like Kosaraju’s algorithm or Tarjan’s, I could see it works well but had no idea where these come from. I mean these algorithms are so elegant and seems magically come from some genius. Indeed, theoretical basis of computer science today was developed by small number of highly talented people in 1970’s and 80's. I remember that I felt like I would never be able to come up these noble algorithms.

Time has passed and now I’m curious about computer science fundamental again. In this article, I try to…

Recently, in my friend community slack, we discussed how much average salaries of software engineers in Japan have been raised in a recent few years. One of my friend, who owns his startup company says that his company has seen sudden increase in hiring cost these 2 years because the average salaries for software engineers has surged.

The conversation reminds me that, as a software engineer, I feel strong demands on new technology to dramatically increase the engineer productivity. I mean the surge in engineer’s salary indicates that software engineering is requiring specialized skill or real world experiences more and…

Recently, I had a discussion in my team around transaction management in micro-services. It is well known that it’s hard to implement transaction in micro-services oriented architecture. In this article, I try to write down my current understanding of transaction management in micro-services architecture. I’m not doing precise technical discussion. Rather, I’m examining an idea that how to connect the several concepts around the distributed transaction management.

Recap: Transaction

Let’s recap what’s the transaction at first. Personally, I felt something mysterious and difficult from the term “transaction”. But, I realize tht it’s actually a pretty simple concept.

Think about a simple example…

Just for fun for holidays, I took a look at a linear algebra text book which I used in my university and wrote python code to calculate inverse matrix. I was interested that elementary operations of matrix can be represented by matrix itself. So, I wrote calculation algorithm by using multiplication chain of elementary matrix. I know the implementation has very bad performance (Yes, it’s O(N⁵). surprisingly bad) than gaussian elimination (O(N³)). However, it’s still useful to see elementary matrix based implementation actually works as it is easier to understand the concept of inverse matrix and its calculation methodology.

Examples of Calculated Inverse Matrix

木田元「存在と時間の構築」読書メモ (Japanese Only)






1.“This is a pen” の”is”。そのものの性質を指し示す。

2.“There is a pen” の”is”。そのものが現実にあることを指し示す。

つまり、1.”This is”の用法は人間のメタな事物の認識作用を表している仮想的なものであるのに対し、2. ”There is”の用法は、現実世界における事物との複雑で有機的な出会いを指し示していると分析されます。概念存在を指し示す「is」と現実存在を指し示す「is」と言い換えても良いかもしれません。

日常の基本動詞「is」に隠れている2つの異なる用法を指摘することで、人間が認識している存在には、概念存在と現実存在の2種類の区別があることを指摘し、近代哲学や自然科学は、1.”This is a pen” の概念存在を示す”is” しか上手く扱えてなくて、2.”There is a pen” の現実存在を示す”is” はうまく扱えていない、と分析しています。

ここで重要な点は、2.”There is”の現実存在を示す”is”は、1.”This is”で示さる概念存在と現実世界の事物を1:1に対応させている、という単純なことではなくて、そもそも目の前にある複雑でかつ時間的に変化する事物を肉体的に直感的に捉えている表現である、と分析している点です。つまり、近代哲学や自然科学は、概念が先にあった上でそれに対応する現実があることを暗黙裡に仮定している、そしてそれは一つの世界の見方でしかなく常に有効な方法論ではない、とされています。

この指摘は教師ありの機械学習を用いて何かしらの現実的な問題を解こうとしたことがある人であれば、ピンとくるのではないでしょうか。例えば、ResNetが画像に紐付いたラベルを上手に言い当てることができたとします。しかし、現実には教師データ中のラベル定義そのものが応用の場面場面において揺れ動く。そして、人間はそのずれにいともたやすく臨機応変に対応しており、この効果をなんとかして吸収する必要があることが、すぐに明らかになります。ResNetが解いている問題が、静止した概念存在を認識するタスクであることに対して、実際に人間がやっている認識はさらにもう少し複雑な認識をやっている。この、2項対立と、1.”This is” と2."There is” の2種類の存在認識の対立が重なって見えてきます。

この議論が行われたのは1920年代、1930年代とインターネットもコンピュータも存在しない100年前です。しかしその理論によって、SNS上のFake Newsや機械学習による認識結果と実応用における認識との誤差が課題となっている2020年現在のコンピュータ産業を取り巻く状況を説明できるように感じました。1”This is X”の用法で切り取られた概念としての存在が、コンピュータやネットワークによって強調されて、2.”There is X”で示される現実世界の事物 と見分けがつかなくなる。そもそも異なる2種類の認識作用を履き違えることで、うまくいかないことが出てきている。


Dependency Injection

Dependency Injection is a powerful design pattern when you write your systems in object oriented(OO) way. In OO, your system would be divided into a lot of objects which is responsible for small functionality. It allows you to write simple logics and unit tests. However, we have to manage a lot of objects. Those objects might have multiple, nested, and complicated dependency chains. You can do these objects dependency management with plain Java, of course. But, it is getting very painful when the number of objects is getting large. Here, we want more structural way to manage objects dependency. …

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store