Pull to refresh
46.33

Perfect code *

How McConnell bequeathed

Show first
Rating limit
Level of difficulty

DSL (domain-specific language) implementation with macros

Level of difficulty Medium
Reading time 8 min
Views 853
Abnormal programming *Programming *Perfect code *Compilers *
Opinion

image
This is a translation of my own article


The release of NewLang language with a brand new "feature" is coming, a remodeled version of the preprocessor that allows you to extend the language syntax to create different DSL dialects using macros.


What is it about?


DSL (Subject Oriented Language) is a programming language specialized for a specific application area. It is believed that the use of DSL significantly increases the level of abstractness of the code, and this allows to develop more quickly and efficiently and greatly simplifies the solution of many problems.

Conditionally, we can distinguish two approaches to DSL implementation:


  • Development of independent syntax translators using lexer and parser generators to define the grammar of the target language through BNF (Backus–Naur form) and regular expressions (Lex, Yacc, ANTLR, etc.) and then compiling the resulting grammar into machine code.
  • Development or integration of the DSL dialect into a general-purpose language (metalanguage), including the use of various libraries or special parsers / preprocessors.

We will talk about the second option, namely the implementation of DSL on the basis of general-purpose languages (metalanguages) and the new implementation of macros in NewLang as the basis for DSL development.

Read more →
Total votes 2: ↑2 and ↓0 +2
Comments 2

Systematic coding and digital signature

Reading time 10 min
Views 2.5K
Cryptography *Perfect code *
Tutorial

Once the Teacher asked the Author:

Are there methods of redundancy introducing at an informational level, other than those that are studied by the theory of error-correcting codes? Emphasizing that he is talking about information redundancy, the Teacher thus made it clear that the question does not imply various ways of energy redundancy introducing, which are well studied in communication theory. After all, the noise immunity of information transmission is traditionally assessed by means of a threshold value that is calculated as the ratio of signal energy to noise energy. It is known that the methods of the theory of error-correcting codes offer an alternative solution, allowing energy saving.

After a cogitative pause, the Author answered in the affirmative, following intuition rather than rational knowledge. Upon hearing the answer, the Teacher noticed that this is a wrong conclusion and there are no such methods.

However, over time, the Author began to suspect that the immutability of the paradigm formulated above could be questioned.

Read more
Rating 0
Comments 0

Example of How New Diagnostics Appear in PVS-Studio

Reading time 4 min
Views 488
PVS-Studio corporate blog Information Security *Perfect code *C++ *C *

PVS-Studio new C++ rule


Users sometimes ask how new diagnostics appear in the PVS-Studio static analyzer. We answer that we draw inspiration from a variety of sources: books, coding standards, our own mistakes, our users' emails, and others. Recently we came up with an interesting idea of a new diagnostic. Today we decided to tell the story of how it happened.

Read more →
Rating 0
Comments 0

COVID-19 Research and Uninitialized Variable

Reading time 2 min
Views 1.1K
PVS-Studio corporate blog Open source *Programming *Perfect code *C++ *

0796_covid_sim/image1.png
There is an open project COVID-19 CovidSim Model, written in C++. There is also a PVS-Studio static code analyzer that detects errors very well. One day they met. Embrace the fragility of mathematical modeling algorithms and why you need to make every effort to enhance the code quality.

Read more →
Total votes 2: ↑2 and ↓0 +2
Comments 5

Finding Typos in the GTK 4 Project by PVS-Studio

Reading time 16 min
Views 535
PVS-Studio corporate blog Open source *Perfect code *C *Development for Linux *

0793_GTK_4_continue/image1.png


You may have already read a recent article about the first PVS-Studio run and filtration of warnings. We used the GTK 4 project as an example. It's about time we worked with the received report in more detail. Our regular readers may have already guessed that this article will be a description of errors found in the code.

Read more →
Total votes 6: ↑5 and ↓1 +4
Comments 1

Why PVS-Studio Doesn't Offer Automatic Fixes

Reading time 4 min
Views 642
PVS-Studio corporate blog Programming *Perfect code *C++ *C *
Why PVS-Studio Doesn't Offer Automatic Fixes

Static analyzer PVS-Studio can detect bugs in pretty complex and intricate parts of code, and coming up with appropriate fixes for such bugs may be a tough task even for human developers. That's exactly the reason why we should avoid offering any options for automatic fixing at all. Here are a couple of examples.
Read more →
Total votes 4: ↑2 and ↓2 0
Comments 0

Part 2: Upsetting Opinions about Static Analyzers

Reading time 4 min
Views 1K
PVS-Studio corporate blog Perfect code *C++ *C *
Единорог грустит

By writing the article "Upsetting Opinions about Static Analyzers" we were supposed to get it off our chest and peacefully let it all go. However, the article unexpectedly triggered robust feedback. Unfortunately, the discussion went in the wrong direction, and now we will make a second attempt to explain our view of this situation.
Read more →
Total votes 7: ↑6 and ↓1 +5
Comments 0

Why it is important to apply static analysis for open libraries that you add to your project

Reading time 7 min
Views 707
PVS-Studio corporate blog Open source *Programming *Perfect code *C++ *
PVS-Studio and Awesome header-only C++ libraries

Modern applications are built from third-party libraries like a wall from bricks. Their usage is the only option to complete the project in a reasonable time, spending a sensible budget, so it's a usual practice. However, taking all the bricks indiscriminately may not be such a good idea. If there are several options, it is useful to take time to analyze open libraries in order to choose the best one.
Read more →
Total votes 1: ↑0 and ↓1 -1
Comments 1

Dark code-style academy: line breaks, spacing, and indentation

Reading time 4 min
Views 2.2K
Abnormal programming *Programming *Perfect code *

Hey guys! Let me walk you through the next part of our dark-style code academy. In this post, we will discover some other ways how to slow down the reading speed of your code. The next approaches will help you to decrease maintenance and increase a chance to get a bug in your code. Ready? Let's get started.

Read more
Total votes 1: ↑1 and ↓0 +1
Comments 1

Dark code-style academy: spoil if statement

Reading time 3 min
Views 1.9K
Abnormal programming *Programming *Perfect code *

image


Do you want to raise your salary? Do you want always to be in demand? Do you want to have your job as long as you want? It is absolutely real! You just need to change the way you write your code. Basically, you need to increase your job security. You have to write code which will be almost impossible to maintain for everyone except you. And in these series of articles, I will tell you how to achieve it. Welcome under the cut.

Read more →
Total votes 3: ↑3 and ↓0 +3
Comments 0

Static Analysis: baseline VS diff

Reading time 6 min
Views 1K
PVS-Studio corporate blog Programming *Perfect code *Development Management *Product Management *
Translation
If you use static analyzers, you will have, sooner or later, to address the task of making their integration into existing projects easier, where fixing all warnings on legacy code is unfeasible.

The purpose of this article is not to help with integration but rather to elaborate on the technicalities of the process: the exact implementations of warning suppression mechanisms and pros and cons of each approach.

image1.png

Read more →
Total votes 5: ↑5 and ↓0 +5
Comments 0

How to introduce a static code analyzer in a legacy project and not to discourage the team

Reading time 8 min
Views 1.5K
PVS-Studio corporate blog Programming *Perfect code *Product Management *DevOps *


It is easy to try a static code analyzer. But it requires skills to introduce it in the development of an old large project. If the approach is incorrect, the analyzer can add work, slow down development, and demotivate the team. Let's briefly discuss how to properly integrate static analysis into the development process and start using it as part of CI/CD.
Read more →
Total votes 1: ↑1 and ↓0 +1
Comments 0

The Anatomy of LuaJIT Tables and What’s Special About Them

Reading time 10 min
Views 2.6K
VK corporate blog Programming *Perfect code *Designing and refactoring *Lua *
I don't know about you, but I really like to get inside all sorts of systems. In this article, I’m going to tell you about the internals of Lua tables and special considerations for their use. Lua is my primary professional programming language, and if one wants to write good code, one needs at least to peek behind the curtain. If you are curious, follow me.


Read more →
Total votes 28: ↑28 and ↓0 +28
Comments 0

What does «clean code» mean in 2020?

Reading time 9 min
Views 6.1K
JUG Ru Group corporate blog IT systems testing *JavaScript *Perfect code *.NET *

«Clean Code» and a clean cat

There is nothing developers enjoy better than arguing about clean code: Dan Abramov, for example, has recently fueled the hype with his blog post, «Goodbye, Clean Code».

However, “clean code” per se doesn’t even have a clear definition. The main book on the subject is Clean Code, where Robert «Uncle Bob» Martin states that there are perhaps as many definitions as there are programmers. But he doesn’t walk away from the fact with a conclusion that there’s no reason to discuss clean code, rather — compare several definitions and highlight general ideas. Therefore he cites the views of several outstanding programmers on what clean code is.

So we have also become interested in what people in 2020 think of clean code. Have the views changed since the publication of the book? Do opinions vary in different IT fields (maybe backend developers perceive the idea of clean code differently from testers)?

This spring, Uncle Bob comes to St. Petersburg to give talks at our three conferences: they are about .NET development, testing and JavaScript. Therefore, we’ve asked speakers from each of those conferences to share their opinion on clean code so we could compare the opinions of the industry experts in 2020.

We've already published the results in Russian, and here's the English version. Since the topic is known to provoke discussions, feel free to give your own definition or argue about those already given!

UPD: When we posted this article, Uncle Bob had our conferences in his schedule. Unfortunately, the situation has changed. We updated this post on March 12, to avoid any misunderstanding.

Read more →
Total votes 10: ↑10 and ↓0 +10
Comments 0

C++ Inliner Improvements: The Zipliner

Reading time 3 min
Views 702
Microsoft corporate blog Programming *Perfect code *C++ *
Visual Studio 2019 versions 16.3 and 16.4 include improvements to the C++ inliner. Among these is the ability to inline some routines after they have been optimized, referred to as the «Zipliner.» Depending on your application, you may see some minor code quality improvements and/or major build-time (compiler throughput) improvements. 

Read more →
Total votes 2: ↑2 and ↓0 +2
Comments 0

MobX or Redux: Which is Better For React State Management?

Reading time 5 min
Views 19K
Website development *JavaScript *Programming *Perfect code *


In JavaScript, state management is a hot of discussion these days. When it comes to implementing state management, developers often find it challenging dealing with boilerplate code in Redux. Hence, MobX has proved to be a good alternative to Redux which gives the same functionality with less code to write. However, both state management tools work well with React.

Let's first have a look at the common things between the two:

1) Both support time-travel debugging
2) Both contain open-source libraries
3) Both provide a client-side state management
4) Both provide huge support for React native frameworks

In this blog, we have listed all the pros and cons of both state management solutions. It will help web developers to choose the best one for their next project. Before discussing this, we have compared both Redux and Mobx based on some parameters as given below:
Read more →
Total votes 1: ↑1 and ↓0 +1
Comments 0

Complexity Waterfall and Architecture on Demand

Reading time 10 min
Views 1.5K
Website development *Python *Programming *Perfect code *

Logo


When talking about "bad code" people almost certainly mean "complex code" among other popular problems. The thing about complexity is that it comes out of nowhere. One day you start your fairly simple project, the other day you find it in ruins. And no one knows how and when did it happen.


But, this ultimately happens for a reason! Code complexity enters your codebase in two possible ways: with big chunks and incremental additions. And people are bad at reviewing and finding both of them.

Read more →
Total votes 5: ↑5 and ↓0 +5
Comments 0

For professors' note: use PVS-Studio to get students familiar with code analysis tools

Reading time 4 min
Views 1.5K
PVS-Studio corporate blog Programming *Perfect code *Studying in IT

Picture 1

Our support chats and some other indirect signs showed that there are many students among our free users. Here's the reason: PVS-Studio is now more often used by professors in courses related to software development. We are very pleased with this, and we decided to write this small article to fall under notice of other teachers. We are pleased that students become acquainted with the methodology of static code analysis in general and the PVS-Studio tool in particular. Our team will try to contribute to this trend.
Read more →
Total votes 24: ↑23 and ↓1 +22
Comments 0

Detecting in C++ whether a type is defined: Predeclaring things you want to probe

Reading time 4 min
Views 1.6K
Microsoft corporate blog Programming *Perfect code *C++ *
Last time, we used SFINAE to detect whether a type had a definition, and we used that in combination with if constexpr and generic lambdas so that code could use the type if it is defined, while still being accepted by the compiler (and being discarded) if the type is not defined.

However, our usage had a few issues, some minor annoyance, some more frustrating.

  • You had to say struct all the time.
  • If the type didn’t exist, the act of naming it caused the type to be injected into the current namespace, not the namespace you expected the type to be in.
  • You must use the struct technique with an unqualified name. You can’t use it to probe a type that you didn’t import into the current namespace.

We can fix all three of the problems with a single solution: Predeclare the type in the desired namespace.

Read more →
Total votes 13: ↑12 and ↓1 +11
Comments 0
1

Authors' contribution