Hi all!
1. Proposal
- “Generally developers believe that you need TypeScript or Flow if you want type safety for JavaScript. This article we will explore a third alternative to achieve those same goals using just JSDoc comments and Visual Studio Code as your editor. Technically, we are going to use TypeScript but not for compiling our code. Instead we’ll use it to check the types of our JavaScript code during code time using JSDocs comments and type inference.” - reference
- I would like to have a jsdoc for python to specify in the comments the types I will use in python functions. So… I call this “semantic poo in def in python”… it’s similar to jsdoc
- Keywords are: static, private, private, void, public, string, int, float, boolean in def or comments in def as:
2. The problems to be solved
- The current problem I would like to solve is legacy applications, old applications made in Java that I would like to migrate to Python.
- This issue can help Java developers who want to migrate Java applications to Python for a specific reason.
3. rules
3.1 - Case 1: keyword def(…): # // code to be executed …
# Main or myMethod with: static|private|public|void
static def functionName(parameters): # // code to be executed ...
private def functionName(parameters): # // code to be executed ...
void def functionName(parameters): # // code to be executed ...
public def functionName(parameters): # // code to be executed ...
3.2 - Case 2: keyword def(…): # // code to be executed …
# Main or myMethod with: string|int|float|boolan
string def functionName(parameters): # // code to be executed ...
float def functionName(parameters): # // code to be executed ...
int def functionName(parameters): # // code to be executed ...
boolean def functionName(parameters): # // code to be executed ...
3.4 - Case 3: @type in “pydoc similar to jsdoc” def(…): # // code to be executed …
3.4.1 - case 1: case1.py
# @type def {public} and parameter{void}
def public Main():
#@type def {static, int} and parameter{int, int}
def static int myMethod(int x, int y):
return x + y
# @type def {public, static, void} and parameter{args:any}
def public static void main(args*):
print(myMethod(5, 3))
print(Main()) # Outputs 8 (5 + 3)
3.4.2 - case 2: case2.py
def public Main():
def static int myMethod(int x):
return 5 + x
def public static void main(args*):
print(myMethod(3))
print(Main()) # Outputs 8 (5 + 3)
3.4.3 - case 3: case3.py
# @type def {public} and parameter{void}
def public Main():
# @type def {static, void} and parameters{age: int} name A name to use.
# Create a checkAge() method with an integer variable called age
def static void checkAge(int age):
# If age is less than 18, print "access denied"
if (age < 18): print("Access denied - You are not old enough!")
# If age is greater than, or equal to, 18, print "access granted"
else: print("Access granted - You are old enough!");
def public static void main(args*):
checkAge(20) #Call the checkAge method and pass along an age of 20
# Outputs "Access granted - You are old enough!"
Main()
4. Reasons
- Bringing Java Developers together in Python, Python is an amazing language, but many Java developers I know have difficulty programming in Python because it is something very different from what they are used to doing.
- I’m a Java developer and when I met Python I fell in love
- Pydoc would be to help specify the types in the def like jsdoc in Typescript
- This could help Java developers like Javascript to migrate to Python
- There are many legacy applications that I would like to easily migrate to Python… This could be done if there was a pydoc for it as specified here
5. Notes
- What do you guys think of the idea?
- I would like positive and negative feedbacks
- My intention is to help the Python community and the Java and Javascript community
6. Why is this interesting?
- It is much easier to create modules and functions with Python than with classes.
- Creating classes is something that I believe is much more complex than creating modules and functions. In part because modules and functions are independent.
- Microsoft created a language called F# that is made for object programming and not object-oriented programming.
- What I’m proposing here is object programming. Which is partially done with functions and modules. With “pydoc” we can have object programming which in my opinion is “better than object-oriented programming”.
7. References
- Type Safe JavaScript with JSDoc. JSDoc Comments Can Provide Powerful… | by TruckJS | Medium
- Use JSDoc: @type
- https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html
- Java Method Parameters
- Java Variables - Javatpoint
- How to create a (python-like) NewType in typescript - Stack Overflow
- TypeScript for Python Developers. A quick introduction to TypeScript for… | by Anton De Meester | Analytics Vidhya | Medium
- Python equivalent of Typescript interface - Stack Overflow
- F# docs - get started, tutorials, reference. | Microsoft Docs