What is the 'expression problem'?

前端 未结 3 1937
刺人心
刺人心 2020-11-30 21:05

I have a rough idea about what this is but if someone has an explanation of the \'expression problem\' that they think is succinct and intuitive I would love to hear it.

3条回答
  •  半阙折子戏
    2020-11-30 22:05

    The idea behind the problem is that text is 1 dimensional. Even if you have lines and columns, you generally read it, word by word, line by line. So does the compiler.

    And you try to represent some kind of 2 or more dimensional data in it. For example a table in row-mayor order looks like this:

    ((A, B, C), (D, E, F), (G, H, I))
    

    In this representation, it's quite easy to add a new row at the end, without touching the rest:

    ((A, B, C), (D, E, F), (G, H, I), (J, K, L))
    

    But adding columns is problematic a bit, you need to touch it 4 different places:

    ((A, B, C, M), (D, E, F, N), (G, H, I, O), (J, K, L, P))
    

    You generally run into this problem in practice, when dealing with abstract classes: it's quite easy to add a new subtype as a new module, but when you add a new abstract method, you'll need to touch all the modules and add it; you need to do the same thing in many places. Normally you make abstractions to protect against these repetitive things.

    There is no solution to this problem as long as you use 1D representation.

    The solution to this problem would be an editor that can let you edit these table like things like a real table and not like text (in an Excel like view, where you can conveniently add new columns and rows).

提交回复
热议问题