What is soft coding? (Anti-pattern)

前端 未结 5 1362
无人及你
无人及你 2021-01-04 00:32

I found the Wikipedia entry on the soft coding anti-pattern terse and confusing. So what is soft coding? In what settings is it a bad practice (anti-pattern)? Also, when cou

5条回答
  •  悲哀的现实
    2021-01-04 00:52

    Ola, a good example of a real project that has the concept of softcoding built in to it is the Django project. Their settings.py file abstracts certain data settings so that you can make the changes there instead of embedding them within your code. You can also add values to that file if necessary and use them where necessary.

    http://docs.djangoproject.com/en/dev/topics/settings/

    Example:

    This could be a snippet from the settings.py file:

    num_rows = 20
    

    Then within one of your files you could access that value:

    from django.conf import settings
    ...
    
    for x in xrange(settings.num_rows):
       ...
    

提交回复
热议问题