
Foojay Podcast #66: Let's Talk About Java Code!
In this Foojay podcast, we dive into a few articles that were published recently and focus on code.
- Igor Kulakov of JetBrains gives us his insights into the tool he created to find duplicate content in documentation.
- Rijo Sam explains how you can generate real random values and how he created a train departure display.
- Maxillian Arruda explains in a very detailed post the different ways to construct a complex Java object.
- And we start with Wim De Troye about the code changes he had to do in a project that got upgraded from Spring Boot 2 to 3.
Video
Podcast Apps
You can listen and subscribe to the Foojay Podcast on:
- Spotify
- Apple Podcasts
- And most others…
Guests
- Wim De Troyer
- Maximillian Arruda
- Rijo Sam
- Igor Kulakov
Links
- https://foojay.io/today/the-proper-way-to-define-configuration-properties-in-spring/
- https://foojay.io/today/make-the-life-of-your-developer-clients-easier-with-smart-builders/
- https://foojay.io/today/pseudorandom-number-generator/
- https://foojay.io/today/crafting-your-own-railway-display-with-java/
- https://foojay.io/today/duplicate-finder-for-text-requirements/
Content
00:00 Introduction of the topics and guests
00:55 Wim De Troyer
03:27 Pro or contra Lombok?
06:09 BeanValidation as part of the solution
07:40 Generating a config JSON file
08:50 Maxillian Arruda
09:19 What is a complex object?
12:09 Using records to simplify object creation
14:48 Telescoping constructors
16:08 Static factory method
19:09 Builder pattern
21:00 The risks of rewriting a project
23:00 Thread safety in object creation
27:53 Rijo Sam
29:07 java.util.Random is not fully random…
30:20 About SecureRandom, seeds, and blocking algorithms
34:16 Vaadin railway display
37:43 Getting railway data from an open API
38:44 It’s a PET project together with Rijo’s partner Ancy
40:22 Runs on a Raspberry Pi
41:18 The next project…
41:34 Igor Kulakov
43:02 DRY principle in documentation
43:37 How the tool works an integration in JetBrains products
44:54 Test-first approach in the project
47:10 Not using AI (yet) to avoid extra cost, local systems could be integrated
48:22 Input data the tool can handle
49:14 Highlights of the blog (and following) post(s)
54:35 Outro
Transcript
Automatically generated from the audio, so it can contain errors in names and technical terms. Suggest a correction.
[0:00] In this Foojay podcast we dive into a few articles which were published recently and focus on Java code welcome to the FJ podcast all your news about OpenJDK Igor kulakov of jet brains gives us insights in the tool he created to find duplicate content in documentation riam explains how you can generate real random values and how he created a train departure display maximilan Aruda explains in a very detailed post the different ways to create a complex Java object and we start with whim detroyer who wrote his first blog post for Foojay the proper way to define configuration properties in Spring we talked about the code changes he had to do in a project that got upgraded and how he discovered and solved the problems in that process and we also discussed whether lombok should still be used or replaced with Java records we did a long overdue migration on one of our applications which kind of got like basically nobody wanted to do it so I had a fun time in December while it was a bit calm to do that migration so this application was on Spring Boot 2 and the goal was to bring it to Spring boot 3 and it managed to
[1:18] Compile rather quickly I used open rewrite also a little bit for that which really helped with the migration but the problem was is that I got some weel runtime errors and one of them was due to configuration properties which were Bound in when I was running the application in Spring Boot 2 no longer being bound when I was running in Spring Boot 2 and that was a very strange issue for me is it really a change in the spring boot so that there’s a change in Spring boot which caused to this caused this problem I compared the release notes of spring Boot 2 and spring boot 3 and I compared those I read also Al through the Java do of spring Boot 2 and spring boot 3 more specifically the documentation on configuration binding and what I found was that in Spring Boot 2 you were more more at Liberty let’s say to just Define your Getters and sets Define a Constructor but now spring brute 3 will notice for instance that you have a Constructor in your properties and it will assume that you want Constructor binding it will heavily favor Constructor binding if there is a Constructor to be found and so what
[2:34] Happened in the piece of code that I show that I showed in my article is that I had a Constructor which had one argument one final field which was picked up by a required ORS Constructor an annotation which generates a Constructor just with the final fields which is something that lombok does and so what happens is spring things it it’s Constructor spring assumes you want Constructor binding spring will bind your configuration properties but it will only call the constructure which has this one argument so the only final field that I had and the other variables that used to be bound in spring boo 2 were no longer bound in Spring Bo 3 because the Binding only happens via the Constructor and that took a while to thebook but yeah you mentioned lbook there are a lot of people Pro and a lot of people Contra yeah was the problem caused by lombok or was it not used in the right way or should lombok not be used at all it’s not caused by lombok because lombok I guess you should I guess the thing was that lombok was misused and I guess also the thing was that lombok
[3:51] Also masked a little bit to problem for me because I don’t see a Constructor you see an annotation obviously so you kind of make that link that there is a Constructor but there’s a little bit of an indirection there so you don’t immediately start thinking ah there’s a Constructor so ah there’s probably Constructor B so one part of the issue was that it masked the problem a little bit and then the second part of the problem is that we were already on Java 17 so we were already we already had access to records the configuration Clause was not well designed anyway it could have been it could have been a record we would have not have a need for lombok we would not have a need for the gets and Setters annotation no need for the required ARS Constructor all that is provided for you if you just use records for which they are meant to be used they’re immutable data carriers and that’s exactly what configuration is you just buy it at startup time and it’s not supposed to change during your during the Run of your application you’re not supposed to change it yourself at least would you
[4:56] Say that lombok can be removed from for instance your project thanks to the records I there’s still a few places where we use and I would even say abuse slook you have to be careful at the entity layer you can use lombok at the entity layer but you have to watch out using some annotations I think a lot of developers just blindly copy paste lombok and just put it on a CLA Without Really knowing what they’re doing I think it still has their is its uses for instance I really like the Builder annotation that lombo provides I think that’s very nice and I think that Java does not really have a nice alternative build into the language they’re working on something I think the JDK maintainers for records which has something similar for records and some sort of Builder pattern but that’s not there yet so I think a lot of things lombok provides are very useful still but you just have to know when and how to use them like any tool basically it’s a bit of magic underneath and that’s a bit what we see in the evolution of java things which were introduced by libraries like lombok because they were missing missing in the
[6:04] In the Java system now they get introduced with all the evolution that were happening okay in your article you also mentioned Bean validation how did it help to solve that specific problem as I said I refactor to a record because that seemed to me like a more maintainable solution but I was also annoyed by the fact that solution luckily it got caught by tests not when I launched the application in a test environment or what have you but this also could have been avoided had we used Bean validation and bean validation is basically a specification that defines some annotations which you can place on your fields on your closet which declaratively provide validation for instance not not null not blank on a string when it does can be not when it can’t be null or can’t be blank those sort of things and it’s backed by an implementation I believe that’s a hibernate validator for spring and all of this works very seamlessly in the spring ecosystem you just place a dependency and everything works out of the box basically with little configuration you add those those
[7:16] Variables and then what you have what you get is startup time safety which is basically if those variables which you expect to not be null or null during startup time spring will simply not boot up yeah and that’s exactly the goal of spring boot they making a lot of standard things easier that you don’t need to do them exct I love it I love it I also learned from your post that the file spring configuration metadata. Json gets generated at compile time yes what can you do with that file so that’s a little bit of a bonus because I don’t think that really is needed to solve the problem I had at hand but while you’re at it you might as well include that that’s an annotation processor provided by Spring you just have to add that on your dependencies at compile time which basically goes through all your configuration classes picks up the annotations and The annotation processor will write a compile time a Json file the this file name that you mentioned and it will write some hints the type of the variables and this Json document which you can also supplement which
[8:29] Own configuration if you wanted to can be used by for instance an IDE to provide autoc completion to provide click through to go immediately from your properties file to a field in your pojo Clause all these nice things which depending on your ID are very nice I know that intellig has really nice support for this so it’s a nice bonus maximilan Aruda is a ju leader for Sho Java in Brazil an open source contributor to Jakarta and nosql software engineer and he recently also published his first Foojay post in this post make the life of your developer clients easier with smart object Builders he explains with a lot of details and example code the different ways how you can construct complex Java objects so The Logical first question is what is a complex object any object that is hard to create in your application well My article is focused on how our customers client of your code am I right it’s not it’s not focused on final solution because well when the application is running the production we are looking for the reach out the goals for our customer clients or and use
[9:49] It them all right but I well as software developer in a company that I’m working on we know that most often 1% of our times we are managing code we are maintaining the code and we are actually using code from another one and we always facing problem with that because some some developers in the past create some codes that we need to that you need to create that you need to manage and so on and sometimes it’s hard to do this because well on the time the code was not designed to be usable to bring a e way to use it and I think okay what is the complex object well is any object that it’s hard to create it’s hard to manage it’s hard to figure out and sometimes it’s hard to create those things and we need to looking for the source code you need to looking for the documentation and you spend a lot of time with that am right you spend a lot of time then why not to create an object in a easiest way to help our client customers our developers to create a good software so and delegate this responsibility regarding
[11:30] The structure the way that you are creating your object to the compiler compiler is a is amazing too that we can get benefits with that right so instead of just to try to do by your own so am all right because well users humans put every in the code and by the way am all right every any kind of bug in a code is put from Human right so why not to create an is just way to use compiler and any kind of tool in our favor so that’s there reason why I think that one thing that changed in the direction of the compiler are the records so we don’t need a lot of geter Setters anymore if you KN use those those new type of java objects we had lombok in the past and still use it by in a lot of projects do you think that records can replace Almost all cases where you have a lot of getter Setter code Java records is the most I think is most UTI feature that brings the Java developer a lot of benefits than drawbacks for example you can of course you don’t need more scaffolds to create GS and Setters and so on because I think it is a end pattern you just put get inide in our object because
[13:01] You you’re broken the how can I say the encapsulation concept of your code of your object and I think that Java can help developers to create immutable objects you can how can I say instead of to care about gets Etc you just create your record easiest and also you can put that thing as a dto or vo value object in your code and so I think it fits what you used to do with pojo in the past in the article I get to start from the apoo because we know that many companies are migrating from java 11 to Java 17 and 21 it’s amazing but we know that a lot of companies especially companies that are consolidating the market has old Java Pro programming pro programs and we need to update them and just use the feature by just to okay I know that is good I would do that I think that is more valuable to understand why it’s so important why we need to use that so that’s the reason why I I’m getting starting from the podo to show why it’s better to use a records instead to put gets and sets I think it’s more important thing this is erise the rule in your team when
[14:47] We understand how those things happen I learned a lot of your from your article can you explain for instance what telescopic Constructors are I didn’t know the term I used the way of programming but I didn’t know that there was a name for it so what is it exactly I F I found out this term in a Java effective book from Joshua block and on that time I thought to myself oh my God what is this term what it means because telescope telescope is something that he used to see the Stars the space bodies and so on for example the mo and so on and I realized that well when we are creating an object that we don’t need the details of this object we don’t need to zoom on it to create it am I right so telescope is something that helps you okay I need to create this object in this specific way so I need to do a zoom on it I need to figure out their attributes and I can use that so this is the reason why telescope name is something related that so I love it this way and indeed there are a few a lot of examples in the article to illustrate it what I also didn’t use
[16:09] A lot in my way of programming is the static Factory methods like you describe so I really love the examples again that you give and they really explain it in detail so for instance create a notification with attachment is an object which has a lot more parameters that you can Define but this one will create one for you which has a notification and an attachment so I think this the way of creating these static methods and how you name them in your example really explain how they should be used in the codes is that the main advantage of this way of creating objects yeah I think the static metod Factory is one special one because you can name it you as you said you can be explicit what we are doing what we are want am I right and also this kind of factory method you can get more power from the o o o or oriented object programming because you don’t need to work only with the type that it’s it’s it’s it’s resulting because you can’t change it you can use some subass to result that so I think that you get you can get more flexibility you can put some
[17:42] Logic and you can fit with this thing and of course put the your code in explicit way to tell the developer that you use your method to understand what’s happening okay as you mentioned creating a notification with attachment so what I need to create that thing so and you know I put some some arguments there and people you feel it in order to create the object but also it comes with thr backs if you have a method like that with a lot of arguments you will end up with the same drawbacks that you use on a constructure you need to figure out which arguments we need to put and the ordered and so on so I think that’s the reason why for film arguments only this is a good PN in my opinion after that I think another patterns can help you better as as I mentioned the Builder Builder pattern you can use that to get un flexible and easiest way to create this kind of object using a fluent interface and so on but I think this is the way that I try to bring this content so should we conclude that a builder pattern is the best solution for really complex objects with a lot of
[19:18] Values yeah I it’s it’s hard to just say what you need to do what you don’t need to do because it depends of the contest that you’re trying to resolve and sometimes you need to deal with a lot of objects and sometimes for your theme because you need to consider that right you need to consider your theme not just the way that you understand the world because it’s it’s a particular way to see the world and it’s a subjective to say that oh this object is hard this object is complex or it’s not complex it’s it’s depend of your team you need to understand the most of the people in your team understand what you’re doing this is the key I think of the success it’s the key of to keep the code updated sometimes the people say oh I don’t like Java because Java is a old one language but man if you are code is a it’s EAS to thing is bringing money why not to keep that you don’t need to go to another language to feel that you are working in a updated program programming you know what I mean so I think that when your team are is aligned with you and the code is
[20:45] Normaliz it in your team is better solution so focus on to make your team reach out the goals because everyone is on the same boat all right I agree because the projects where I have been involved where rewriting was the goal because we want to change language yeah you end up again with an unfinished project because in that previous project there were certain implementations to solve a specific problem that you maybe don’t know anymore so if you go to another language you will introduce these same same problems which were solved in the past so I agree that it’s better to evolve an existing application and then move from it from java 8 to a later one and make use of what’s what’s all new in this language then yeah we starting from scratch is rarely a good idea I think it’s like a microservices applications right sometimes we see people getting start from microservices and trying to create an big service a big solution put a lot of microservices but the context is not so well the limited so why not to get start from the monolith and after that let the code show the
[22:16] Necessities you know what I mean so if you are creating an object and this object is hard to create it maybe you need to put an a kind of engineering there to help you help the people that you manage this object so that’s this is a complex object that you that the Cod show you showing to you right so I think you could keep those things simple not Simplicity one but simple to be maintained to be grow it and so on so that’s the reason why I think is a good way to get start and reach out your goal so the success and so on one other thing that I found remarkable in your article is that you a few times point out that there’s a problem with threat safety if you’re in constructing complex objects that you also need threat safety into account what can go wrong there threads is something that you need to care about if you are using this kind of solution in a mood trading programming and in Java by the way is whole whole created over threads I’m right Java it’s TI to threads and when we got threads we can share objects between the threads and it could be brings problems to developers
[23:49] And the problems that’s hard to reproduce it’s hard to find out the way because sometimes if you don’t put those things in the good way the wrong situation the invalid State comes and we need to figure out where is it but it’s after the problems happens so it’s the worst situation that you got right so but when we are creating object and we need to share it we need to care about how to synchronize the way that you read and you write your attributes in the object when we are creating a builder probably we are defining the types between the C the build build method and well developers can do everything you know right developers are creative you want so they could be think okay I will create a builder and they will share that between the trads because maybe I can create an object in a how can I say multiple trads and so on you know what I mean developers are creative on so but we to care about that because otherwise you will end up in a undesired situation so that’s the reason why I think that we need to care about that so if you are creating an object one rule of come that I follow
[25:15] Is oh never create an object with invalid State because you created an invalid State you end up in desired situation so Builders is a is an object that you need you are in a way to create an object yet so you need to care about that so that’s the reason why I think threads is something that we need to care about when we are working on and that’s the reason why we are using to recommend to people to use immutable objects because if you’re creating mutable objects you are safe you are trade safe by the way right because any thread you change your object anymore so but if you’re creating an object on as I said using a PO play Old Java object you need to care about that put some synchronize or maybe lock lock object and so on trying to figure out those things but that that’s why that’s the reason why I put this kind of information just to have the people to understand that so I don’t know if and maybe I should put more information about that but I think well one friend of M when I when he Le read the article he told me oh Max you can broke this one in multiple
[26:39] Articles you don’t need to put everything in a specific one but oh I like to it’s it’s a pretty long article but it makes sense because you really build up on you start with a simple object and you make it complexer and you have all the Alternatives so for me it’s a perfect article you don’t need to break it up which would be a good case is a second article a followup and more Improvement so we’re looking forward to more content of you on Foojay actually I I’m I’m learning a lot about gather is apis that is impr Improvement on the spring API part so I’m trying to write something there and pretty soon I will publish it that as well so I must thank for Jo Foojay for this opportunity to share a little bit what I know because I learn a lot from FJ so why not to contribute so this is the key of Open Source and the food J how can you say help the people to increase their career so I’m love it so thanks so much riam is a Java chapter lead originally from India and now living in the Netherlands where he also presents A J he has several articles on Foojay and I selected
[28:04] Two of them for this podcast let’s start with Pudo random number generator the secret behind Santa’s gift back I didn’t know Santa is a Java developer I was writing this article during the holiday season and then it’s it’s all about Christmas movies and Santa so then I found okay this is a nice correlation with sudo random number generators so I end up comparing those so the problem here is we always use in programming random number generators and we use random numbers in all the cryptographic encryption we use random numbers but the here important thing we need to understand is the random numbers we are using is not always random MH they are always based on an algorithm that appears to be creating random numbers same like Santa’s gift bag like if you look at from outside Sanda is always giving a random gift to the child but Sanda knows exactly which gift to give to which child and which is the next one so you’re saying that if we’re using java. u. random what we get is actually not that random that’s what we call pseudo random number it’s a big word it’s not always random there is two
[29:22] Random number generators that is so hard to use in programming programming it’s it’s based on natural phenomena and it’s a different class but the random javar random. u. random or the secure random they all are zudo random number generators and the what we are getting is not always random they are good enough to be random good enough but this could be a problem if you look into security related items correct yes if we are using java. u. random that is not used for security purposes at all so it’s mainly used for where you need efficiency more than security so for examply if you are creating a game application where you need to mimic the behavior of a dice or a card shuffling those places you can always use java. u. random it’s not secure but it’s efficient and fast but when coming to a cryptographically secure algorithms we always need to use a java. secure random so that’s always a better choice for everything related to security so why don’t we use it all the time because it’s less efficient less F correct correct Whenever there is a cryptography need we use a secure
[30:43] Random that’s a best choice but the drawback here is it’s not that efficient it will take time it is not that fast as the other one so we need to understand something here is all the zero random number generate are based on an initial value called seed and the main difference between the secure random and java. u. random how the seed is selected in java. u. random the seed is selected from the clock of the system it’s always predictable that’s why it’s not that secure the other one the secure random always uses some random data from the operating system that’s why it’s most secure and yeah if we create a secure random instance it always select an algorithm based on your operating system and in most cases I would say you always stick with what we are getting as a default but if you really want to have a specific use case you can also select a different algorithm algorithm but here also a cat when you’re selecting a specific algorithm you need to remember a about the blocking behavior of those algorithms I have an example a few years ago and I was working on a project where we encrypt data set of data of
[32:10] Customers for an onboarding process and what we are doing we collect some data we encrypt it and we send it to another external party so we Implement everything and we went live and during the first day of on vent La production we noticed that a lot of customers are getting time M then during the debug system we debugging we found out that we are by default we are using a random number generator algorithm which is blocking in Behavior what exactly is doing is whenever we have a new request we ask operating system hey I need a random number and operating system find out that number and give us to give it to us but when the request is so high on the first day the operating system was not able to deliver that much an numbers then the request went in weight State and blocking State and in the end customers end up in a in a Timeout M so we sold it by moving it to a non-blocking algorithm algorithm yeah so we have to take take into account it’s slower it can lead to threat issues but it will give you a secure random number correct so even the non-blocking one nonblocking algorithm is less secure
[33:33] Than the blocking algorithm so it’s also you need to consider like how security you need how much security you need what’s your application exactly is okay and in the blog post you have a few of these algorithms described like sh one prng native prng and you have a link I see to all these these algorithms and what you can use so if people are really interested in finding one that fits their system they can find it there okay it’s also important forny if you’re working on a Windows laptop you’re selecting an algorithm you need to make sure that it’s also there for in your target system maybe your server is learning on link so yeah yeah that’s also important to consider another project that you described on Foojay it’s less technical it’s more fun it’s a private project and it’s what is the title exactly crafting your own Railway display with Java there’s a very nice picture in the blog post showing I think your living room do you really have an oldfashioned station clock in your living room yes yes so that project is like really close to my heart and it’s I always have some use for it so
[34:50] Some background I’m living living in near to like 15 minutes from my station by bike and I like to travel with public transport here the situation is if I am not on time I need to wait a long time for the next train so we only have trains for in a gap of 30 minutes so especially this is a problem during winter called mornings I need to wait outside so I thought okay this is not working I need a solution then I thought why can’t we create display with some custom data in my living room so that I can always look I don’t need to open app look into the timing so I can always see what time so I added some data like status of the train I can see whether the train is already in the station or not or like time to departure like how much time I have the train to catch the train so for example if that if there is 12 minutes I can always cycle cycle to cycle slowly and if it’s less than 12 minutes I need to cycle more fast but it’s interesting to see and it’s a nice project it’s still there in my living room okay working per and what did you use so it’s it’s a user interface
[36:06] Application it really shows a timetable like you see display in the station what did you use to display it I use wadin for the back end Java jakata and for the UI it’s I use wadin M did you already use Vaden before or is this the first time you created this is my first time using W so when we started this project back end was always fine like Java I can use Java jakata which I’m really familiar of but the front end when okay I need to display something right so then I was thinking okay what should I use I’m not a friend and developer and I’m not familiar with those Frameworks I saw react angula JavaScript all those confusing and somehow I ended up in Vin which was a lifesaver for actually for Java developer like me it was so easy I can write the code in Java if you want you can do some CSS that’s it other than that it was so easy and their documentation is also clear enough we can use it simply I was using few components and within one or two hours I have an initial UI which can display my API a response so it was so nice for me yeah I’ve used Fen a long
[37:23] Time ago I think over 15 years and then found it back a few years ago and indeed I really love the framework it’s so easy to create a user interface a we website fully written in Java and they have nice components you can really easily build a layout like that I like by the way how you how your screen looks like so it’s filled with the train data of the station where you live closest by how easy was it to get that data in the Netherlands it’s it’s fairly easy like all the data about the Netherlands Des Railway is publicly available and they are well documented with API so you need to go and create an account in the API portal and then with the API key you can subscribe to the apis and just start using it that’s it and they give it for free or only you have lied use right now it’s free I don’t think they have a paid plan we can also get data from other Railways via d Railway that is also possible I try with getting some German train data it’s possible with the same apis you only need to select the station you need UIC code of a station UIC code is a unified code for all the railway stations and if
[38:41] You have that code of a German railway station you can try getting it it’s a it’s a pet project I definitely like it because it looks nice it really fills a gap for something you needed and it brings you to a higher nerd level as I can say because you did this together with your partner correct yes my partner she’s also a Java scotl developer so we do like something like this to learn learn projects so whenever there is something coming up or we experimented with together and this was something it took some time for us to like she was in charge of doing the UI part and I was in charge of doing the back end part it’s some time it took some time for us to finish this one but it in the end it was really nice project working together learning each other sharing things and we were changing it day today that’s what interesting like we found something okay for example our station sometimes have bu instead of train so they if a train is cancelled then they have best so we want to display display a picture of BU on our display so we did that so many different things we also we can now switch to any
[39:54] Station in Netherlands I can also do some train sporting sporting if I want I can move to Amsterdam and see okay what are the trains going from Amsterdam so it took some time but we really enjoy the process working together yeah I think it’s a very good approach to learn one new thing in each project so in this case it was Fen for you and for your partner so it’s really great that you have this kind of project together and create such an amazing tool you’re also running it on a Raspberry Pi correct correct correct some Foojay articles were really helpful that’s the first time we are setting up rasy P when we were running we created the project we had okay we need to figure out where we need to run we need to put it into cloud or what we can we need to do as cloud is not that financially good so we thought okay why can’t we run it in Raspberry Pi in our system so we purchase a Raspberry Pi we installed Java with SDK SDK man and then yeah it was working easily even we did some debugging in Raspberry Pi with the visual studio provided in Raspberry Pi so it’s already up on the up on the wall
[41:05] So Raspberry Pi is also fitted so we have a remote keyboard and mouse which is connected to the Raspberry Pi and if you want to make some code changes we can actually do in the Raspberry p if you want what does the next project what will it look like already have something we have few ideas but not yet concrete to sh but probably we will share it in our next FJ article in the coming months so we were working on it yeah Igor kulakov is a technical writer at jetbrains focusing on intelligy IDE he is also a hobbyist developer and is working on a tool to find duplicate content in documentation sets he wrote about his project on Foojay and I asked him what challenge he wants to solve the blog post talks about one of my B projects it’s a long r one because I’ve been technical writing since 2016 and ever since this time I was facing this challenge of duplicate content because first I didn’t have tools to reuse it like when you write something once and then when you need a similar chunk of content some somewhere else then you just include include that it turns out that’s not the only
[42:27] Challenge because the other part and more more harder more hard one is finding what to extract to a reusable component or a reusable snippet of text because especially in big teams it happens that many people write something similar and due to lack of communication or due to like organizational differences just those people don’t know they are working on something similar so you want to avoid that the same text is written a bit different on another place so you want to find all the spots with similar content that you can unify it correct yes yes it aligns with dry principle don’t repeat yourself of course it gets overused and abused sometimes because you cannot extract everything to reusable component but some things that you definitely need to extract and this not only applies to programming this also applies to content how do you run this is this part of your build process of generating docs or is it a tool you run from time to time just to find these spots for now it’s just a standalone utility that you can of course you can run it on CI with every build or you can or it has like a user
[43:56] Interface face which you can use like for a periodic inspection of your sources I use it once in a while so that’s not a like regular routine there is an ongoing effort to integrate this into writer side like in jet brains we have a authoring tool called writer side it’s now Early Access and what we want to do is to make this tool highlight duplicate or fuzzy matches are right as you type so you don’t have to run anything specifically you just do your technical writing or content writing or you write some content and then the tool automatically notifies you that something similar is present elsewhere in other module in other file depending on the settings in the blog post you’ve taken a test first approach so you define some text fragments that are pretty similar and then try to find similarities isn’t that a difficult thing with text it could be so large and so yeah if if if there’s one word different is it already different enough how do you define how similar it should be there are several parts to like recognizing to determining if a text is a duplicate or not because first is
[45:30] Chunking because if you have a very big very large document then part of it might be 100% similar and the rest of the document might be might differ so the first question is how to chunk that because with structured content it’s easier for example with XML you can take XML tag as basic unit and with Json that’s also easy but then you have like plain text for plain text which unit of text should be basic like a paragraph or maybe it’s written without paragraphs at all then how you how do you recognize if a sentence uses different wording but the meaning is the same for example if if one word changed is it already different or not so I took a very basic approach very similar to fuzzy search which is which doesn’t account for differences in wording with similar meaning so of course we could like do it using embeddings and like Parts to try to understand semantics of text first and then compare it but I decided to go with a more basic approach to compare just lecal graphically like not letter by letter but something similar and I guess a lot
[47:11] Cheaper than using some AI system behind it to really try to figure out if it’s the same content based on your feeling or whatever is important there so you don’t need AI that means that everything just runs in j logic so there’s no external service called correct that’s absolutely correct but now with local models we can do everything locally and probably but that would still be slower probably next step would be course filtering with a just basic algorithm finding some candidates for the duplication and then running AI over there them because then the number of things to check would be much smaller MH and then it would be quicker and more efficient and we could probably even use something external for that if if that gives better quality so I think there is no contradiction between these two approaches they could be used along side what kind of input can you give to the tool is it XML Json HTML whatever what can it handle for now it’s XML PL text a markdown and a markdown X and that’s it but I’m planning to add more types of sources for example I was
[48:46] Surprised but that’s a very popular request for Google spreadsheets and Excel tables because people are often asking on s like how do I find cells that are similar not identical like 80% similar so that seems to be a valid request and I’m planning on adding this so it’s very hard in a podcast to go through the sources but luckily you have added a lot of source examples in the blog post can you maybe describe what was important and what you highlighted in that blog post this was the second part of this of the series first was the introduction and the second one the one we are talking about is about requirements so I decided to start by writing tests I usually don’t do that but in this project I was lucky enough to have like because I thought about requirements for a while and I knew that this core require ments would not change and you basically can in this case you can set in stone or rather in code this requirements and it works well because as I said before I’m not a professional developer but I have an impression that many like software
[50:18] Projects suffer from vague requirements or Ever Changing requirements oh yeah and this probably makes it difficult to like make test tests like that would make a specification for like for the lifetime of the application of the project but in this project it first it’s relatively simple and second I knew requirements in advance so I decided to start by writing tests that’s not test driven development exactly but something like that so that would not only allow me to catch like regressions afterward but that’s also kind of like declaration that the app should work this way you see it’s a part of a series so there is a next part coming about the app yes the next part I want to dedicate to the actual implementation of the algorithm by the way it’s already on GitHub and it’s open source so you can if you’re curious you can familiarize yourself with like the sources and in the next part I’m I want to like dive into implementation but I’m still thinking how to do that because I want to ideally make that interactive so that people can not only see pictures
[51:54] And read paragraphs but probably play around with some of the parts of the algorithm right in the browser and I’m thinking whether to write that in JavaScript for or just a toy application in the browser just to Showcase how the algorithm works and the primary application the project itself is in cotlin but that doesn’t affect how algorithm works so probably one more way to implement men that could be cotlin compiled to web assembly but I haven’t yet started I’m I’m very excited about this technology but I haven’t yet started with it and I don’t yet know if it’s possible for browser to read local files because apparently some browsers allow that and some are not some don’t allow that so yeah I want to play around and find what what’s the best solution and yeah then I will publish the next part there will be one more about optimization that’s my favorite part because I’m very keen on optimizing things of course like you can optimize it forever and there are some there is some lowlevel stuff which I know nothing about but it’s very very rewarding
[53:30] To make some basic optimizations to see your app gain in speed like 5x just because you improved your equals or code method yeah because you’ve taken the test first approach you can really do these benchmarks if you change your implementation you can really test if if things are faster yes but that’s at the same time that’s a little bit complicated because the application is IO bound so if operating system is reluctant to give files then the Benchmark is screwed and it’s very inconsistent it can fluctuate like plus minus one second and sometimes it can be several seconds thanks a lot thanks for your blog post for the detailed description looking forward to the next episodes and thank you for contributing your content to F thank you too and thank you for having me on your podcast thanks to my guests for their amazing content on fu. and joining this podcast thank you for listening Please Subscribe in your podcast app or on YouTube keep an eye on Foojay for future articles and podcasts about development and everything related to the Java world see you give me a give me a j give me
[54:56] The friends of OpenJDK
Found a mistake, or something to add? Edit this page on GitHub











