New snippet ideas #1925
Replies: 5 comments 2 replies
-
MotivationJava is a widely used programming language. I think that having a collection of practical Java code snippets would greatly help 🌟 many categories in the community: students, teachers, developers, experts etc. ExampleHere's an example: It's a small method with JavaDoc comment and some keywords around. /**
* Returns the sum of 2 given numbers
*
* @param a The first integer number.
* @param b The second integer number
* @return The sum of 2 integer numbers, of type int
*/
private static int sum(final int a, final int b) {
if (a == 0 && b == 0) {
return 0;
}
return a + b;
} ConclusionBy adding Java, this project may become more valuable for developers and communities across different areas. What do you think? |
Beta Was this translation helpful? Give feedback.
-
Simple React useReducer ExampleMotivationThe useReducer Hook seems complicated at first but one can easily bridge the gap between useState and useReducer with a simple example and some explanation. There is already a redux reducer snippet available in the react folder but it focuses on "Writing readable reducers in Redux". My snippet would be different in that it would show why reducers are necessary and would not use redux. Code example // Reducer function
function reducer(state, action) {
if (action.type === 'increase') {
return {
count: state.count + 1
};
}
throw Error('Unknown action.');
}
// Define reducer
const [state, dispatch] = useReducer(reducer, {count: 0});
// Output example
console.log('Count value: ', state.count);
// Change value example
function handleClick() {
dispatch({type: 'increase'});
} Questions
|
Beta Was this translation helpful? Give feedback.
-
Web accessibility is an important topic for frontend developers nowadays because it ensures that websites and web applications can be used by all people, including those with disabilities or impairments. Reason for web accessibility
i think we must have snippet on it what you think about it ? |
Beta Was this translation helpful? Give feedback.
-
Hi @Chalarangelo , I am thinking of adding a new snippet to check whether a number is even or not using bitwise operation. Can I proceed with the PR? |
Beta Was this translation helpful? Give feedback.
-
New snippet and collection ideas should be first discussed with the community before making a pull request to add them. Start discussing your ideas below, open a new discussion for a more specific idea or help someone else refine theirs and create their first PR!
Beta Was this translation helpful? Give feedback.
All reactions