How do you program differently in dynamic languages?

前端 未结 15 1801
南笙
南笙 2021-02-01 03:37

How would someone who really knows how to take advantage of dynamic programming languages approach programming differently than someone working in a static language?

I

15条回答
  •  别跟我提以往
    2021-02-01 04:10

    One way I typically find myself taking advantage of dynamic programming languages is in simplifying and clarifying syntax. If I'm representing a database, for example, the syntax I use for interacting with it can be much cleaner if I can dynamically load properties and methods on the database object for its tables, the tables and rows for their columns, and so on. The difference might be between:

    $row = $db->getTable('user')->getRow(27);
    $row->setValue('name', 'Bob');
    

    and

    $row = $db->user->getRow(27);
    $row->name = 'Bob';
    

    The 'visual noise savings' of the second form really starts to add up when you're doing complex things.

提交回复
热议问题