Differences Between Dynamically-Typed-Languages and Strongly-Typed-Languages
Tag: Ruby
Tag: Rails
Category: jekyll
Category: update
Category: git
Category: database
Category: PostgreSQL
Category: websocket
Category: ruby
Category: projects
Category: Redis
Category: mysql
Category: Mac
Category: Node
Category: NPM
Category: PM2
Category: nodejs
Category: Meteor
Category: Nginx
Category: gitLab
Category: Rails
- Why Ruby on Rails is better than Python Django?
- How to use Hotwire turbo in Rails 6 with Webpacker?
- Rails 6 Credentials (master.key and credentials.yml.enc)
- Rails Console
- JIRA-Atlassian-Connect-App-Django
- Rails 4 5.0 Session Cookie AuthenticityToken
- Rails Active Storage
- Rails 5 Source code Research
- 微信支付
- Rails零星笔记
Category: Homebrew
Category: CentOS
Category: FreeSwitch
Category: Ruby
- Ruby on Rails 8
- RESTful API
- Ruby on Rails 7
- Study from Ruby official website
- Ruby-Metaprogramming
- Ruby连数据库的问题
- rbenv使用
Category: Vim
Category: javascript
Category: React-Native
Category: Wechat
Category: homeland
Category: JavaScript
Category: Docker
Category: RubyMine
Category: Authorization
Category: RESTful-API
Category: Proxy
Category: Deploy
Category: Devise
Category: Bootstrap
Category: Active_Storage
Category: github
Category: Android
Category: cloud
Category: ssh
Category: python
Category: reactjs
Category: markdown
Category: ShadowSocks
Category: Code
Category: rails
Category: code
Category: Django
Category: Python
Category: DRF
Category: Fish
Category: Yarn
Category: Material-UI
Category: CSS
Category: aws
Category: uwsgi
Category: nginx
Category: docker
Category: React
Category: Enzyme
Category: Jira
Category: Interview
Category: JetBrain
Category: PyCharm
Category: ESLint
Category: Rails6
Category: NVM
Category: ssl
Category: tencent
Category: CI
Category: jenkins
Category: GitHub
Category: Credentials
Category: master.key
Category: Webpacker
Category: Turbo
Category: Hotwire
Category: Bootstrap5
Category: Flutter
Category: Clash
Category: Tor
Category: proxy
Category: Build
Category: SwitchyOmega
Category: Chrome-extension
Category: SQLAlchemy
Category: Algorithm
Category: Rails7
Category: Data
Category: Structure
Category: CPP
Category: Languages
Category: Golang
Category: Typescript
Category: Rails 8
Overloading
-
In strongly typed languages, overloading is very common, since at compile time, the compiler can check the types of the arguments. But in dynamically typed languages, overloading is not supported by dynamically typed languages. since the arguments passed can be any type, and no exception until during runtime it could cause an exception if the argument type does not match.
-
One of Python’s way is to use singledispatch to implement similar features. Another way is like Ruby, do it manually, like using
*arguments
, and check each argument’s type by usingtype(arg)
. -
Ruby do it by using multiple arguments and checking those arguments https://stackoverflow.com/questions/9373104/why-doesnt-ruby-support-method-overloading
-
JavaScript do it in similar ways as Ruby.
Interface
- Interface includes a set of abstract methods which need to be implemented in classes. If a method is not implemented in class, the interface designer likes to through an exception (or IDE support warning it already) in compile time in strongly typed languages like Java.
How does Ruby implement interface?
Like this:
module ThisIsJustACommonModule
def some_method_1(arg1)
raise NotImplementedError, "You must implement the `some_method_1` method"
end
end
Include this module in your class, and define some_method_1
is your class. That is all. If you didn’t implement it, there is no compile time error (compile is not a thing Rubists concern), only runtime error.
How does Python implement interface?
https://stackoverflow.com/questions/2124190/how-do-i-implement-interfaces-in-python
from abc import ABC, abstractmethod
class AccountingSystem(ABC):
@abstractmethod
def create_purchase_invoice(self, purchase):
pass
@abstractmethod
def create_sale_invoice(self, sale):
log.debug('Creating sale invoice', sale)
# Create a normal subclass and override all abstract methods:
class GizmoAccountingSystem(AccountingSystem):
def create_purchase_invoice(self, purchase):
submit_to_gizmo_purchase_service(purchase)
def create_sale_invoice(self, sale):
super().create_sale_invoice(sale)
submit_to_gizmo_sale_service(sale)
So Python does it by applying inheriting from ABC
(Abstract Base Class) and using @abstractmethod
decorator in your class.
If the abstract methods
are not implemented, there will be an exception to fail the instantiating of the class.
How does JavaScript implement interface?
-
Interface means that some methods must be included in some classes, JavaScript doesn’t need this. If you want those methods contained in some classes, just define them. If you didn’t define them, there will be a method not found exception. Until during runtime, no one knows the exceptions. This is the way how dynamically typed languages do it.
-
Language versions
2024 Nov C++ 23 (20 wildly used) Java 23 Golang 23 Node.js 23 C# 9 Python 3.13 Ruby 3.3.6