[VV61] Learn Kotlin, synchronized & lock, security matchers, readibility, code review, scrum value
Learn Kotlin: short introductory course by W3School
Kotlin is a modern, trending programming language.
Kotlin is easy to learn, especially if you already know Java (it is 100% compatible with Java).
Kotlin is used to develop Android apps, server side apps, and much more.
???JAVA CERTIFICATION QUESTION: synchronized and locks
Given:
public class MsLunch {
private long c1 = 0;
private long c2 = 0;
public void inc1() {
c1++;
}
public void inc2() {
c2++;
}
}
How do you make c1 and c2 incrementing atomic?
* set inc1() and inc2() as synchronized
* set inc1() synchronized while inc2() stays the same
* wrap the body of inc1() and inc2() in a synchronized block with the same lock
* wrap the body of inc1() and inc2() in a synchronized block with different lock
#java #certificationquestion #ocp
Answer: wrap the body of inc1() and inc2() in a synchronized block with different lock
Synchronized statements are useful for improving concurrency with fine-grained synchronization.
Suppose, for example, class MsLunch has two instance fields, c1 and c2, that are never used together.
All updates of these fields must be synchronized, but there's no reason to prevent an update of c1 from being interleaved with an update of c2
— and doing so reduces concurrency by creating unnecessary blocking.
Instead of using synchronized methods or otherwise using the lock associated with this, we create two objects solely to provide locks.
See:
public class MsLunch {
private long c1 = 0;
private long c2 = 0;
private Object lock1 = new Object();
private Object lock2 = new Object();
public void inc1() {
synchronized(lock1) {
c1++;
}
}
public void inc2() {
synchronized(lock2) {
c2++;
}
}
}
Use this idiom with extreme care. You must be absolutely sure that it really is safe to interleave access to the affected fields.
???? SPRING CERTIFICATION QUESTION: Which is the recommended securityMatchers method ?
* antMatchers
* mvcMatchers
* regexMatchers
* requestMatchers
#spring #certificationquestion #vcp
Answer: requestMatchers
In Spring Security 5.8, the antMatchers, mvcMatchers, and regexMatchers methods were deprecated in favor of new requestMatchers methods.
The new requestMatchers methods were added to authorizeHttpRequests, authorizeRequests, CSRF configuration, WebSecurityCustomizer and any other places that had the specialized RequestMatcher methods. The deprecated methods are removed in Spring Security 6.
These new methods have more secure defaults since they choose the most appropriate RequestMatcher implementation for your application. In summary, the new methods choose the MvcRequestMatcher implementation if your application has Spring MVC in the classpath, falling back to the AntPathRequestMatcher implementation if Spring MVC is not present (aligning the behavior with the Kotlin equivalent methods).
To start using the new methods, you can replace the deprecated methods with the new ones. For example, the following application configuration:
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((authz) -> authz
.antMatchers("/api/admin/**").hasRole("ADMIN")
.antMatchers("/api/user/**").hasRole("USER")
.anyRequest().authenticated()
);
return http.build();
}
}
can be changed to:
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((authz) -> authz
.requestMatchers("/api/admin/**").hasRole("ADMIN")
.requestMatchers("/api/user/**").hasRole("USER")
.anyRequest().authenticated()
);
return http.build();
}
}
QUOTE ???
Optimizing Code Readability
Research shows that reading and navigating code consume more time than typing.
To enhance readability, we focus on three optimizations: making code easy to scan, emphasizing expressive layout, and adopting a compact format.
?? Code easy to scan
Leveraging human pattern recognition and standardizing non-essential elements in code makes accidental complexity fade into the background.
Consistent layouts help distinguish code behavior and structure within classes.
?? Code expressive layout
Choosing meaningful names is key to code clarity.
Code layout is also expressive.
领英推荐
Teams often adopt automatic formatters as a starting point, fine-tuning manually.
This hand-finished style aligns with code intent, surpassing automated formatters.
?? Code Compact format
Maximizing on-screen content reduces cognitive load.
Traditional long comments and whitespace were suitable for older technology, but modern IDEs offer syntax coloring and cross-linking.
Every pixel should aid code comprehension, with layout serving this purpose effectively.
?? Code is like poetry: everything in the text has a purpose.
Code review: why and how?
?? The Importance of Code Reviews
Code reviews are crucial for improving code quality and reducing defects.
However, misconceptions and bad experiences have led some programmers to dislike them.
In some organizations, formal reviews are mandatory, with architects or lead developers conducting them, resulting in bottlenecks and inefficiencies.
?? Avoiding Rigid Processes
While some organizations may require rigid code review processes, most benefit from a more flexible approach.
Formal reviews can make reviewees feel judged and slow down the development process.
Instead, the focus should be on sharing knowledge and establishing coding guidelines, promoting collective code ownership.
?? Effective Code Review Practices
Effective code reviews involve gentle, constructive feedback and diverse roles in the review meeting to distribute the workload.
Regular code review days with a rotating reviewee pattern and role switching among team members help maintain engagement.
Involving both newcomers and experts ensures a well-rounded perspective.
?? Making Code Reviews Enjoyable
To ensure successful code reviews, make them enjoyable for the participants.
Emphasize knowledge sharing and maintain an informal atmosphere.
Avoid sarcasm and introduce small, enjoyable elements like sharing a meal, which fosters a positive and productive code review culture.
#programmer #programming #code #review #software
SCRUM: So Where Is The Value??? by Steve Trapps
In everything we do, there should be some value. If not, then why do it?
We need to see the value in what we're doing.
???? A Developer
will see the value when they create the changes they've been asked to work on.
However, is there always value in the work that they've done?
Not if it's buggy and nobody uses it.
?? A Scrum Master
will see the value when they see the team working as a self-organising team,
with the stories being moved into "Done".
???? A Product Owner
will see the value when the release is made and they can explain to the stakeholders what improvements have been made.
What would happen though if the market has moved on and what we thought was valuable no longer is?
??????????????Stakeholders
will see the value when more customers come to use the product as it is the market-leading one.
As you can see, to each person involved in the process the value comes at different times.
However, it is only when the product reaches the customer that the true value is attained
Until that time we're carrying "Value Debt".
Assessing project success often prioritizes timescale ? and budget??, but these are indicators, not the core value.
Meeting deadlines alone doesn't add value?; functionality and worth?? matter more to customers.
No Customer will ever buy something due to the product being there on time if the functionality/worth/value isn't there.
In conclusion: We must never lose the value of why we do something.
#scrum #product #value
???? Digital biting dog
#Student> I'm sorry, my dog ate my homework
#ComputerScienceProfessor> Your dog ate your coding assignment?
#Student> ...
#ComputerScienceProfessor> ...
#Student> It took him a couple of bytes
The programming course student is not being truthful when he claims his coding homework was devoured by his dog. The humor in this situation lies in his clever punchline, blending a physical 'bite' with 'digital bytes,' a reference to the unit of memory size in computing, where a byte comprises eight bits.