Hot answers tagged

131

My personal feeling is that improving quality is worth the minor inconvenience of an additional commit log entry, even for small improvements. After all, small improvements count a lot when you factor in the broken window effect. You might want to prefix it with a TRIVIAL: tag, or mark it as trivial if your VCS supports it.


60

It means all of its production rules have a single non-terminal on their left hand side. For example, this grammar which recognizes strings of matched parentheses ("()", "()()", "(())()", ...) is context-free: S → SS S → (S) S → () The left-hand side of every rule consists of a single non-terminal (in this case it's always S, but there could be more.) ...


59

It's because it's important for humans to recognize that functions are not just "another named entity". Sometimes it makes sense to manipulate them as such, but they are still able to be recognized at a glance. It doesn't really matter what the computer thinks about the syntax, as an incomprehensible blob of characters is fine for a machine to interpret, ...


49

You aren't being pedantic, and it is better to resolve them individually. The more atomic a change is, the better -- you don't want a crashing bug fix to be mixed up with 500 comment/typo changes.


48

I think the reason is that most popular languages either come from or were influenced by the C family of languages as opposed to functional languages and their root, the lambda calculus. And in these languages, functions are not just another value: In C++, C# and Java, you can overload functions: you can have two functions with the same name, but different ...


43

Since static members are shared between ALL instances of a class, they have to be defined in one and only one place. Really, they're global variables with some access restrictions. If you try to define them in the header, they will be defined in every module that includes that header, and you'll get errors during linking as it finds all of the duplicate ...


28

In the General Case: Yes It's always worth it to increase the maintainability of your software. Just go for it. If you're just about to ship a release... ... and if you're not the team leader, then check with him/her. Regarding the content of the commit log... I agree with others that you should at least write something make it distinct from "feature"-...


24

I believe you're reading way too much into a simple grammatical construct. Take a look at your list of paradigms, sorted differently for a reason we will get to shortly: Imperative Functional Procedural Structured Declarative Event-Driven Automata-Based Object-Oriented What do the words all have in common? They're all adjectives because they're intended to ...


24

Any such search and replace should be performed with care and each change manually checked to eg avoid "accompany" in a comment becoming "acvendor" with your company/vendor change. As such, two separate searches for "company" and "companies" should not create a significant overhead compared with the time spent inspecting and approving each change. So ...


18

but when we talk about programming with objects, we have to clarify that we are oriented around those objects. Can't we just use objects? Can't we just have objects? Frankly, it's a holdover of history. Functional programming is really function-oriented programming, declarative programming is really declaration-oriented programming... after all don't we ...


18

Lexers are just simple parsers that are used as a performance optimisation for the main parser. If we have a lexer, the lexer and the parser work together to describe the complete language. Parsers that don't have a separate lexing stage are sometimes called “scannerless”. Without lexers, the parser would have to operate on a character-by-character basis. ...


17

They usually aren't. They are removed by the lexer, when source code is transformed from characters to tokens. Then, the parser will get tokens and build an AST. When the parser does its job, comment are already gone, so they don't have to appear in the grammar.


16

I think the limitation you have considered is not related to semantics (why should something change if the initialization were defined in the same file?) but rather to the C++ compilation model which, for reasons of backward compatibility, cannot be easily changed because it would either become too complex (supporting a new compilation model and the existing ...


12

I think refactor is appropriate here, but I sometimes call this cleanup.


12

The three terms that I would consider would be "obsolescence", "deprecation" or "refactoring". Obsolescence is when something that works is phased out. Deprecation refers to a process by which the use of something is discouraged. Depending on the delivery and use of a system, both obsolescence and deprecation must be planned and communicated over time. ...


10

You might be interested to learn that, way back in prehistoric times, a language called ALGOL 68 used a syntax close to what you propose. Recognising that function identifiers are bound to values just like other identifiers are, you could in that language declare a function (constant) using the syntax function-type name = (parameter-list) result-type : ...


10

A "normal" word is pretty much just a subroutine. ...but you can write a user-defined defining word, which change how the compiler works. For example, a definition normally starts with a colon (":") and ends with a semicolon (";"). But if you want, you can (for example) change what the colon does, and in the process change how a word definition is "compiled"...


9

An Abstract Syntax Tree is a data structure that uses structure to eliminate parenthesis and other details of textual representation. Operator precedence, a significant feature of textual representation, is, in the AST, encoded in the structure of the tree: whereas in textual form operator precedence is encoded using operator priority rules along with ...


9

The common way is to say list of string. It comes from the mathematical convention of pronouncing the notation of a function: f(x) is read as "f of x". The convention is as universal as mathematics, so every human language will have a local way of saying it. Even if generics are not functions, they are a parameterized types. So instead of applying a ...


8

In Haskell, the String type is an alias for [Char], which is a regular Haskell list of Char, not a vector or array. Char is a type that holds a single Unicode character. String literals are, unless you use a language extension, values of String type. I think you can guess from the above that String is not a very compact or otherwise efficient representation....


8

You can expand your matrix grammar into an ADT with perfect sharing with a little bit of trickery: {-# LANGUAGE DeriveFunctor, DeriveFoldable, DeriveTraversable #-} import Data.Map import Data.Foldable import Data.Functor import Data.Traversable -- | Type synonym for non-terminal symbols type NonTerminal = String -- | Data type for the right hand side of ...


8

Yes, a BNF grammar contains all the rules you need for lexical analysis and parsing. The difference between the two is a little fuzzy. A good example of a lexical rule in EBNF would be: number = [ "-" ], digit, { digit } ; digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; Usually lexers can be implemented using relatively simple code. ...


8

You mentioned Java and Scala as examples. However, you overlooked an important fact: those aren't functions, those are methods. Methods and functions are fundamentally different. Functions are objects, methods belong to objects. In Scala, which has both functions and methods, there are the following differences between methods and functions: methods can be ...


7

Typos should be added as a commit. Fixing misspelled words or grammatical errors will increase the readability of your code. Using a commit message such as "Fixed typo" or "Fixed typo in file.c" will help you distinguish these commits from other, major code commits.


7

Yes, you should absolutely do this, particularly early on in a project. Why? Two points: You likely won't know if a typo is "critical" or not until it is too late. Some fixes probably don't get fixed because everyone thinks it won't be a big deal. Until it is. Fixing a typo early on and deliberately will be much easier than fixing it after several ...


7

To understand the distinction and the terminology better, it's a good idea to contrast a context-free language like anbn with a context-sensitive one like anbncn. (Notation: a, b, and c are literals here and the exponent n means repeating the literal n times, n>0, say.) For instance, aabbc or aabbbcc is not in the latter language, whereas aabbcc is. An ...


6

Yes. Since epsilon means you can rewrite W as the empty string, acbW -> acb. As you have shown, there are two leftmost derivations for the string acb, which by definition means the grammar is ambiguous.


6

The probable reason for this is that this keeps the C++ language implementable in environments where the object file and linkage model does not support the merging of multiple definitions from multiple object files. A class declaration (called a declaration for good reasons) gets pulled into multiple translation units. If the declaration contained ...


Only top voted, non community-wiki answers of a minimum length are eligible