- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: ruby-code-style/no-cryptic-perlisms
Language: Ruby
Severity: Notice
Category: Code Style
The rule ‘Avoid using Perl-style special variables’ is important for improving the readability and maintainability of your code. Perl-style special variables, such as $0
, $1
, and $_
, while powerful, can make your code less readable and harder to understand, especially for developers unfamiliar with Perl or its influence on Ruby. They can also introduce subtle bugs due to their global nature and the special behavior associated with them.
To avoid violating this rule, you can use the more descriptive aliases provided by the English
library. This library, which is part of Ruby’s standard library, provides human-readable names for Perl-style special variables. For example, instead of using $&
to get the string matched by the last successful pattern match, you can use $MATCH
.
Here’s a compliant code example: Instead of $_
, you can use $LAST_READ_LINE
. Instead of $!
, use $ERROR_INFO
. This makes your code more self-explanatory and reduces the potential for confusion. Example:
require 'English'
puts $LAST_READ_LINE
puts $ERROR_INFO
This practice significantly enhances the readability of your code and makes it more accessible to developers who are not familiar with Perl-style variables.
$! = ' -- '
$@ = ' -- '
$; = ' -- '
$, = ' -- '
$/ = ' -- '
$\ = ' -- '
$. = ' -- '
$_ = ' -- '
$> = ' -- '
$< = ' -- '
$$ = ' -- '
$~ = ' -- '
$* = ' -- '
$& = ' -- '
require "English"
$OUTPUT_FIELD_SEPARATOR = ' -- '
"Lorem ipsum dolor sit amet" =~ /dolor/
print $POSTMATCH, $PID, "\n"
|
|
For more information, please read the Code Analysis documentation
Identify code vulnerabilities directly in yourVS Code editor
Identify code vulnerabilities directly inJetBrains products