A Recommendation for interface-based programming

Posted 张驰Zhangchi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了A Recommendation for interface-based programming相关的知识,希望对你有一定的参考价值。

When implementing custom data structures, it is best to keep methods such as forEach, find and findLast coherent with javascript's interface standards. This is beneficial to the future upgrade of data structure, and also saves you time to remember different realization processes of the same interfaces. Taking forEach as an example [1]:

The forEach() method executes the provided callback once for each value which actually exists in the Set object. It is not invoked for values which have been deleted. However, it is executed for values which are present but have the value undefined.

callback is invoked with three arguments:
  • the element value
  • the element key
  • the Set object being traversed

There are no keys in Set objects, however, so the first two arguments are both values contained in the Set. This is to make it consistent with other forEach() methods for Map and Array.

If a thisArg parameter is provided to forEach(), it will be passed to callback when invoked, for use as its this value. Otherwise, the value undefined will be passed for use as its this value. The this value ultimately observable by callback is determined according to the usual rules for determining the this seen by a function.

Each value is visited once, except in the case when it was deleted and re-added before forEach() has finished. callback is not invoked for values deleted before being visited. New values added before forEach() has finished will be visited.

forEach() executes the callback function once for each element in the Set object; it does not return a value.


In this case, it is not hard to tell that interface-based programming is a time saver. Without interface-based programming, software architecture cannot be low in coupling and high in cohesion.

References

[1]. MDN contributors. (Mar 28, 2022). Set.prototype.forEach(). MDN Web Docs. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach

[2] Title picture from: https://unsplash.com/photos/SYTO3xs06fU

A Recommendation for interface-based programming - AFFiNE Blog

以上是关于A Recommendation for interface-based programming的主要内容,如果未能解决你的问题,请参考以下文章

A Recommendation for interface-based programming

推荐系统--splitting approaches for context-aware recommendation

论文分享:A content-based recommendation algorithm for learning resources

DRN :A Deep Reinforcement Learning Framework for News Recommendation论文解读

DRN :A Deep Reinforcement Learning Framework for News Recommendation论文解读

Check-N-Run: a Checkpointing System for Training Deep Learning Recommendation Models | NSDI‘ 22