There are tactical reasons to adopt strong typehint: easy validation, less code, fashionable. Besides, the first typehints blend in effortlessly with the current application: it is as if typehint was already there. Later, it appears that scalar types paved the way to more substantial code refactoring. Classes emerge from the initial scalar types, code congregate around important values, types gets more complex. Finally, systemic typehint arrives. Type hints become systemic when they help tame the class dependency hell, and help us plan for the new code. During the session, we’ll cover the various stages of using typehints, with their advantages, and when not to overuse them.
There are tactical reasons to adopt strong typehint: easy validation, less code, fashionable. Besides, the first typehints blend in effortlessly with the current application: it is as if typehint was already there. Later, it appears that scalar types paved the way to more substantial code refactoring. Classes emerge from the initial scalar types, code congregate around important values, types gets more complex. Finally, systemic typehint arrives. Type hints become systemic when they help tame the class dependency hell, and help us plan for the new code. During the session, we'll cover the various stages of using typehints, with their advantages, and when not to overuse them.
As the author of an open-source serialization library in Scala, I've undergone a lot of struggle to understand and harness the power of Scala's type system. My library was based on parsing pickled Scala signatures, which was a subterranean and sparely documented feature of Scala 2.8. I wanted to serialize and deserialize options, lists and maps, which required defeating type erasure when serializing while skating by on type erasure when deserializing. I struggled with multiple constructors, checking for annotation types, specialization, more. The new reflection libraries introduced in Scala 2.10 provided easier access to the same information I had been getting from the pickled signatures. This talk will address practical aspects of type mining, providing a library of hands-on examples using the Scala 2.10 reflection API.
There are tactical reasons to adopt strong typehint: easy validation, less code, fashionable. Besides, the first typehints blend in effortlessly with the current application: it is as if typehint was already there. Later, it appears that scalar types paved the way to more substantial code refactoring. Classes emerge from the initial scalar types, code congregate around important values, types gets more complex. Finally, systemic typehint arrives. Type hints become systemic when they help tame the class dependency hell, and help us plan for the new code. During the session, we'll cover the various stages of using typehints, with their advantages, and when not to overuse them.
As the author of an open-source serialization library in Scala, I've undergone a lot of struggle to understand and harness the power of Scala's type system. My library was based on parsing pickled Scala signatures, which was a subterranean and sparely documented feature of Scala 2.8. I wanted to serialize and deserialize options, lists and maps, which required defeating type erasure when serializing while skating by on type erasure when deserializing. I struggled with multiple constructors, checking for annotation types, specialization, more. The new reflection libraries introduced in Scala 2.10 provided easier access to the same information I had been getting from the pickled signatures. This talk will address practical aspects of type mining, providing a library of hands-on examples using the Scala 2.10 reflection API.
This Presentation is the intro. to java programming.
This presentation contain the basics of Java with example in simple language.
This presentation clear your all concept about programming in java and then you can easily make programs in java.
Let’s have some fun with Power Query M languageCédric Charlier
You know how to use Power BI or Power Query to load data from different sources but you want to go further than limiting yourself to the UI? You’re tired to look at auto-generated code and don’t understand the key concepts of this powerful ETL language? Then, this session is for you. During 60 minutes, you’ll learn how to write code in this functional language. Starting with syntax, primitive and structured values; we’ll quickly jump to the creation of expressions and functions and the usage of some recurrent patterns. This session contains many demos and real-life use-cases that you’ll be able to transpose to your own projects.
Functional programming in kotlin with Arrow [Sunnytech 2018]Emmanuel Nhan
Slides from my talk about Kotlin & Functional programming with Arrow which I gave at Sunny Tech 2018 (http://sunny-tech.io)
It showcases how Kotlin is a good fit for functional programming, thanks to Arrow.
Revanth Technologies provides the best specialized Php Online Training & Software training for various Computer IT courses. For more details contact us on 9290971883, 9247461324.
email.id.revanthads@gmail.com.
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...Thoughtworks
3 years ago, Springer decided to use Scala on a large, strategic project. This talk is about the journey the development teams made. Why did they choose Scala in the first place? Did they get what they hoped for? What challenges and surprises did they encounter along the way? And, most importantly, are they still happy with their choice?
This Presentation is the intro. to java programming.
This presentation contain the basics of Java with example in simple language.
This presentation clear your all concept about programming in java and then you can easily make programs in java.
Let’s have some fun with Power Query M languageCédric Charlier
You know how to use Power BI or Power Query to load data from different sources but you want to go further than limiting yourself to the UI? You’re tired to look at auto-generated code and don’t understand the key concepts of this powerful ETL language? Then, this session is for you. During 60 minutes, you’ll learn how to write code in this functional language. Starting with syntax, primitive and structured values; we’ll quickly jump to the creation of expressions and functions and the usage of some recurrent patterns. This session contains many demos and real-life use-cases that you’ll be able to transpose to your own projects.
Functional programming in kotlin with Arrow [Sunnytech 2018]Emmanuel Nhan
Slides from my talk about Kotlin & Functional programming with Arrow which I gave at Sunny Tech 2018 (http://sunny-tech.io)
It showcases how Kotlin is a good fit for functional programming, thanks to Arrow.
Revanth Technologies provides the best specialized Php Online Training & Software training for various Computer IT courses. For more details contact us on 9290971883, 9247461324.
email.id.revanthads@gmail.com.
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...Thoughtworks
3 years ago, Springer decided to use Scala on a large, strategic project. This talk is about the journey the development teams made. Why did they choose Scala in the first place? Did they get what they hoped for? What challenges and surprises did they encounter along the way? And, most importantly, are they still happy with their choice?
Developer testing 101: Become a Testing FanaticLB Denker
In this workshop we will cover the methodologies and three basic levels of testing, then we will deep dive into how to use PHPUnit to achieve developer testing. The tests may not be the prettiest, most robust, or efficient, but you should leave the course with the ability and confidence to write tests for your code.
Topics include: xUnit framework basics and workflows, test classification, asserts, data driven testing, and an introduction to mocking.
This is a beginner course, but seasoned veterans may discover features they never knew.
Just a simple intro to typescript.
Most of the contents are of any OO language, hence slide contents are minimal. If anyone need any further help, reach me out - akhil2369492@gmail.com
-Akhil
Qui a laissé son mot de passe dans le codeDamien Seguy
Qui, de nos jours, laisse encore son mot de passe dans le code? Pour quelles raisons? Et comment éviter de voir ses secrets atterrir en production, ou dans un dépot public? en utilisant Exakat et git-secrets.
Présentation en détail de l'analyse statique : ses fondements en PHP, ses mécanismes internes, les processus d'augmentation des connaissances et de personnalisation des analyses, ainsi que les résultats d'audits.
Revue de parcours des pièges les plus classiques en PHP, entre les références qui pendouillent, les opérateurs et leur précédence, array_merge() en boucle, ou encore les fonctionnalités natives oubliées et les améliorations de PHP 8.0.
PHP has its own treasure chest of classic mistakes that surprises even the most seasoned expert : code that dies just by changing its namespace, strpos() that fails to find strings or arrays that changes without touching them.
Do that get on your nerves too ? Let’s make a list of them, so we can always teach them to the new guys, spot them during code reviews and kick them out of our code once and for all. Come on, you’re not frightening us !
Meilleur du typage fort (AFUP Day, 2020)Damien Seguy
Le typage se propage à tout PHP : la 7.4 l’ajoute aux propriétés, après les arguments et les valeurs de retours. Bien qu’opposé aux choix initiaux de typage faible de PHP, le typage augmente significativement la cohérence du code, son niveau d’auto-validation et les possibilités de dépendances inextricables. Le typage contribue à aider les outils d’introspection, à débuguer le code au plus tôt, et à adopter des techniques de développement comme le motif de l’objet null. C’est un outil supplémentaire, pratique pour les grands projets, et facilement déployé.
https://event.afup.org/afup-day-2020/afup-day-2020-tours/programme/#3246
PHP has its own treasure chest of classic mistakes that surprises even the most seasoned expert : code that dies just by changing its namespace, strpos() that fails to find strings or arrays that changes without touching them. Do that get on your nerves too ? Let’s make a list of them, so we can always teach them to the new guys, spot them during code reviews and kick them out of our code once and for all. Come on, you’re not frightening us !
Déjà, PHP 7.4 toque à la porte, et il arrive les bras chargés de fonctionnalités et de modernisations. Que ce soit les FFI, le support du typage pour les propriétés, l’abandon des nombres real, la covariance, et même la modernisation de strip_tags, array_merge sans argument, et l’imbrication d’opérateurs ternaires : ouf, il va falloir se retrousser les manches. Durant la session, nous passerons en revue les nouvelles fonctionnalités, les incompatibilités, et nous verrons comment préparer son code dès maintenant.
PHP has its own treasure chest of classic mistakes that surprises even the most seasoned expert: code that dies just by changing its namespace, strpos() that fails to find strings or arrays that changes without touching them. Do that get on your nerves too? Let's make a list of them, so we can always teach them to the new guys, spot them during code reviews and kick them out of our code once and for all. Come on, you're not frightening us!
PHP has its own treasure chest of classic mistakes that surprises even the most seasoned expert : code that dies just by changing its namespace, strpos() that fails to find strings or arrays that changes without touching them. Do that get on your nerves too? Let’s make a list of them, so we can always teach them to the new guys, spot them during code reviews and kick them out of our code once and for all. Come on, you’re not frightening us?
PHP a son lot de surprises qui pimente notre vie de développeur : le code qui meurt d’un coup de namespace, strpos qui ne trouve pas sa chaîne et les tableaux qui se modifient sans qu’on y touche. Ca vous énerve vous aussi ? Alors, en 20 minutes, on va dresser un florilège des erreurs les plus vicieuses, comment les corriger et comment les garder loin de votre code. Attachez vos ceintures !
Static analysis is an emerging field, in particular in the PHP world. Reviewing source code at the speed of a computer requires powerful theoretical tools: control flow diagram, abstract syntactic trees, acyclic dependency graph.
If all this seems far and remote from PHP, come and learn how they apply to your favorite language! They are all useful when it comes to detecting early those errors that end up in production, and sometimes, even before the code may compile. We’ll see how to combine all those aspects to build a useful auditing engine.
Static analysis for PHP Static analysis is an emerging field, in particular in the PHP world. Reviewing source code at the speed of a computer requires powerful theoretical tools: control flow diagram, abstract syntactic trees, acyclic dependency graph. If all this seems far and remote from PHP, come and learn how they apply to your favorite language! We'll see how to combine all those aspects to build a useful auditing engine.
Review unknown code with static analysis php ce 2018Damien Seguy
Code quality is not just for christmas, it is a daily part of the job. So, what do you do when you're handed with a five feet long pole a million lines of code that must be vetted ? You call static analysis to the rescue. During one hour, we'll be reviewing totally unknown code code : no name, no usage, not a clue. We'll apply a wide range of tools, reaching for anything that helps us understand the code and form an opinion on it. Can we break this mystery and learn how everyone else is looking at our code ?
PHP 7.3 is already bet3 and we will get the final version shortly after Sinterklaas.
A wide range of new features are already available for testing, including the relaxed syntax for Heredocs, the final comma in function calls, and a crowd of smaller increments.
We’ll review those evolutions, check the incompatibilities, and try to find the in PHP code.
Finally, we’ll present the RFC process that leads to new features : we can start to discover PHP 7.4 together!
PHP 7.3 sera en beta à la fin de l'été, et cible une sortie avant Noel. De nombreuses nouveautés sont prévues de longue date, comme l'évolution de la syntaxe heredoc, ou les , finales pour les appels de fonctions, tandis qu'une rafale de nouveautés se bousculent au portillon, et ont même généré une alpha 4. Nous passerons en revue toutes ces évolutions, ainsi que les incompatibilités, comment les trouver dans du code, et comment fonctionnent les RFC de PHP.
PHP 7.3 sera en beta à la fin de l'été, et cible une sortie avant Noel. De nombreuses nouveautés sont prévues de longue date, comme l'évolution de la syntaxe heredoc, ou les , finales pour les appels de fonctions, tandis qu'une rafale de nouveautés se bousculent au portillon, et ont même
généré une alpha 4. Nous passerons en revue toutes ces évolutions, ainsi que les incompatibilités, comment les trouver dans du code, et comment fonctionnent les RFC de PHP.
Review unknown code with static analysis php ipc 2018Damien Seguy
Code quality is not just for christmas, it is a daily part of the job. So, what do you do when you’re handed with a five feet long pole a million lines of code that must be vetted ? You call static analysis to the rescue. During one hour, we’ll be reviewing totally unknown code code : no name, no usage, not a clue. We’ll apply a wide range of tools, reaching for anything that helps us understand the code and form an opinion on it. Can we break this mystery and learn how everyone else is looking at our code ?
Everyone fear the review of his own code. And to start with, there is no time. Because, what will happen once we have found something to detail ? In fact, a good code review means being ready to discuss a mere few lines, assess the context and evaluate an alternative, or not. It also means that when the code has become a dense jungle, there may hide monsters worse than a few errors. Using automated tools that are not scared by volume, we’ll keep everything under control, without anyone else knowing about it.
Static analysis tools checks PHP code without running them. Fully automated, they bring expertise to review the code, enforce good practices when programming, keep code ready for the next PHP version. PHP 7 has developed tremendously our capacity to audit code. Thanks to AST and return types, it is possible to go deeper and prevent more bugs. During this session, we'll review the current state of static analysis tools, learn what they can find for us, and how to integrate it in the development cycle: security bugs, migration incompatibilities, and directives recommendations. Simply said, better PHP coding.
Machine learning for PHP
Machine learning is teaching the computer how to learn by itself. It is far easier to be done, especially when you have small data set and a good level of expertise in your field. Classifying objects, predicting who will buy, spotting comments in code is achieved with grassy algorithms like neural networks, genetic algorithms or ant herding. PHP is in good position to make use of such teachings, and take advantages of related technologies like fann. By the end of the session, you’ll know where you want to try it.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Generating a custom Ruby SDK for your web service or Rails API using Smithyg2nightmarescribd
Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn how to generate custom feature-rich SDKs that can communicate with any web service, such as a Rails JSON API.
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
7. Typehints as debug tactics
• Set up a typehint
• Wait for the 'Fatal error'
• Fix the calling code, now that you know where it is
• Remove it in production
• Leave it in development
<?php
foo("a");
foo(1);
foo(new x);
foo(array());
function foo(string $s) {
echo $s;
}
class x {
function __toString()
{ return "a"; }
}
?>
8. Your code is already typed
• Typehints are already used in the code
• PHP, and strict_types
• is_string(), is_array(), instanceof…
• Coding conventions
9. Coding conventions
• The type is in the name of the argument
• $string, $array
• $user = new User();
<?php
function shorten($string) {
return substr($string, 0, 5);
}
function getPattern(array $ints) { }
function (StringClass $string) { }
?>
10. Moving type checks to the signature
• is_a(), is_subclass_of(), instanceof, ===
null
• is_string(), is_array()
• (int), (string)…
<?php
function bar($user) {
if ($user === null) {
throw new TypeError();
}
if (!$user instanceof User)) {
throw new TypeError();
}
return $user->validate();
}
?>
11. Moving type checks to the signature
• is_a(), is_subclass_of(), instanceof, ===
null
• is_string(), is_array()
• (int), (string)…
<?php
function bar(Usager $user) {
return $user->validate();
}
?>
12. Moving type checks to the signature
• is_a(), is_subclass_of(), instanceof, ===
null
• is_string(), is_array()
• (int), (string)…
<?php
function bar($price) {
return floor((float) $price) * 1.21;
}
?>
16. Follow the lead
<?php
function bar(string $argument) : string {
return substr($argument, 0, 10) ?: '';
}
?>
Substr() returns string OR false
17.
18. Backward with the return types
<?php
function bar($argument) {
return foo($argument);
}
function foo($x) {
return barbar($x);
}
function barbar($y) : string {
//...
}
?>
19. Forward with caution
<?php
function bar3($argument) {
return foo(null);
}
?>
<?php
function bar($argument) {
return foo($argument);
}
function foo($x) {
return barbar($x);
}
function barbar(string $y) {
//...
}
?>
<?php
function bar2($argument) {
return foo(22);
}
?>
20. Wait for PHP 8.0
<?php
function foo($x) {
if (rand(1, 3)) {
return 1;
} else {
return barbar($x);
}
}
function barbar($y) : string {
//...
}
?>
21. Adoption
• Use it for debugging purposes
• Follow the types that are already there
• PHP
• Your framework
• Propagate your own types
• Return types are easy, argument types need caution
33. Evolution
• Scalar types cannot evolve
• Classes can evolve
• Class types don't need to be complex
• A price is not an int/float
• A path may be a string while a string is not a path
38. • Type hints reduces the number of possible paths in
the code
• Scalar are versatile
• They have a lot of connectivity
• Upgrading scalar types to class types reduce
complexity even more
Scalar types to classes
Evolution
40. Organisation
• Typehinting has impact on the signature of a method
• This impact spreads all over the application
• It introduces a hierarchy of the classes
41. Classes order
Organisation
• A method returns one type
• A method has dependencies on
its arguments's type
• That object must be created
first
• A method has dependencies on
its constructor too
42. Classes order
Organisation
• A method returns one type
• A method has dependencies on
its arguments's type
• That object must be created
first
• A method has dependencies on
its constructor too
45. Classes order
Organisation
• Topological sorting of the classes
• One class has priority over another class when it is used as typehint
• There is no garantee for a single top class :
• Probably several top classes
• With scalar as argument, because they are so easy to tweak
48. Subsidiary questions
Organisation
• Why are there multiple methods with the same typehints?
• Potential double work
• How testable are the classes?
• How many objects do you need to create an instance?
• Can a method reach a specific type of class?
• The needed types may not be available
49. Adding typehints to your code base
• Adoption
• Follow the current code
• Evolution
• Refactor the code, use classes as typehints
• Organisation
• Use typehints to reduce complexity and plan evolutions
50. Subsidiary questions
Static analysis helps you type
• Exakat
• Typehint suggestion report, type inconsistencies and typehint report
• Phpdoctor
• Reports missing types
• Psalm
• Infers typehints on the fly
51. Subsidiary questions
Static analysis helps you type
• Exakat
• Typehint suggestion report, type inconsistencies and typehint report
• Phpdoctor
• Reports missing types
• Psalm
• Infers typehints on the fly
53. Classes order
Organisation
• M1 needs a property
• M2 provides that property
• M2 > M1()
• True in PHP 7.4+
• x::$a must not be accessed before
initialization
• True in PHP 7.0
• Call to a member function bar() on
null