9000
  • Member for 11 years, 1 month
  • Last seen more than a week ago
How to write a very basic compiler
Accepted answer
390 votes

Intro A typical compiler does the following steps: Parsing: the source text is converted to an abstract syntax tree (AST). Resolution of references to other modules (C postpones this step till ...

View answer
How do I handle disagreement in a code review regarding an unlikely edge case?
Accepted answer
228 votes

an obscure case that is extremely unlikely to happen--in fact I'm not sure it is even possible to occur Not having untested behaviors in code can be very important. If a piece of code is run e.g. 50 ...

View answer
Why do so few languages with a variable-type 'operator' exist?
Accepted answer
103 votes

Operators are just functions under funny names, with some special syntax around. In many languages, as varied as C++ and Python, you can redefine operators by overriding special methods of your class....

View answer
Does syntax really matter in a programming language?
Accepted answer
65 votes

Yes it does. If you're in doubt, take APL, or J, or Brainfuck, or even plain and simple Lisp or Forth, and try to understand any not entirely trivial program on it. Then compare to e.g. Python. Then ...

View answer
Why are nested loops considered bad practice?
Accepted answer
63 votes

Nested loops are fine as long as they describe the correct algorithm. Nested loops have performance considerations (see @Travis-Pesetto's answer), but sometimes it's exactly the correct algorithm, e....

View answer
What are some patterns and anti-patterns of application logging?
Accepted answer
62 votes

A few points that my practice proved useful: Keep all logging code in your production code. Have an ability to enable more/less detailed logging in production, preferably per subsystem and without ...

View answer
Should you always program server side for a website?
56 votes

Read about static site generators. These allow you to create a site in a programmatic manner (using templates, data, etc), and not by hand-crafting HTML. The result is a set of static HTML and CSS ...

View answer
A concrete example of Python's "only one way to do it" maxim?
Accepted answer
49 votes

Compared to languages like Perl, Python has a limited number of control constructs: only if and no unless, only for that iterates over sequences and no foreach or C-style for, only while that ...

View answer
Java dev learning Python: what concepts do I need to wrap my head around?
Accepted answer
41 votes

A few points in addition to what was already said: Python is dynamic. Creation of a class is an executable statement, as is import of a module; it can be made conditional. A class can be altered ...

View answer
Why would passing objects through static methods be advantageous?
34 votes

A trivial example: when the instance passed can legitimately be null and you want to incorporate the (non-trivial) handling of this into the method.

View answer
What to say to your boss if they want you to use a global variable
Accepted answer
33 votes

If one object is enough, creating an object every time is a waste, and here your boss may be right. The problem is proper access to that object. A factory-like method with proper visibility which ...

View answer
Working on a branch with a dependence on another branch that is being reviewed
31 votes

You already have a branch on which your every feature branch depends, and which keeps changing. It's called master. The typical way for a feature branch to stay in sync with master is to stay on top ...

View answer
Is it a good practice to declare instance variables as None in a class in Python?
31 votes

1. Make your code easy to understand Code is read much more often than written. Make your code maintainer's task easier (it as well may be yourself next year). I don't know about any hard rules, but ...

View answer
How do you safely delete a piece of code that looks like it's never entered?
30 votes

Identify the code that looks dead (static analysis, etc). Add a log message for every invocation of the allegedly dead code. It's easy with functions / methods; with static members like constants it's ...

View answer
Copy-and-Pasted Test Code: How Bad is This?
Accepted answer
24 votes

Copy-pasted and then edited test cases are often fine. Tests should have as few external dependencies as possible, and be as straightforward as possible. Test cases tend to change with time, and ...

View answer
Should I refactor the code that is marked as "don't change"?
23 votes

Remember the G. K. Chesterton's fence: do not take down a fence obstructing a road until you understand why it was built. You can find the author(s) of the code and the comments in question, and ...

View answer
I feel stuck in the center of Python, How to get past beginner
23 votes

Stop reading books. Go write code using the time now free from reading. Practice. Ponder. Face real problems in real code you write. Then you'll have enough questions that advanced books can answer. ...

View answer
Why was Fortran never used to develop an Operating System?
Accepted answer
21 votes

I'd say that Fortran, even of pre-C times, abstracts the programmer from hardware details too much. No pointer support. If you want to pass large amounts of data between subroutines, you use a COMMON ...

View answer
Can the csv format be defined by a regex?
21 votes

Regex can parse any regular language, and cannot parse fancy things like recursive grammars. But CSV seems to be pretty regular, so parseable with a regex. Let's work from definition: allowed are ...

View answer
Why the ugly keywords in C11?
Accepted answer
20 votes

I imagine that backwards compatibility with perfectly standard code is a more important reason. If you add a keyword that might have been used as a legitimate identifier in previous code, you create ...

View answer
Why using string[] args in all main methods?
19 votes

Console applications predate GUI applications, and these take command-line parameters for very long time (at least from CP/M time, which preceded MS-DOS, which preceded Windows, which preceded Windows ...

View answer
How would I implement a "self-destruct" feature into the free trial version of my software?
18 votes

Just my 2¢. 100% reliable self-destruction is impossible. There will always be a sophisticated way to crack your protection. What you can do is to make using or cracking an expired trial more ...

View answer
Why dynamically typed languages do not let the developer specify the type?
Accepted answer
17 votes

The point of having static typing is the ability to prove statically that your program is correct with regard of types (note: not completely correct in all senses). If you have a static type system ...

View answer
Why does java collections not supply a function for the index of max value?
Accepted answer
17 votes

While there can be exactly one max value in a collection, there can be more than item representing that value. E.g {1, 9, 2, 9, 0} has max value of 9, represented by both elements [1] and [3]. Note ...

View answer
Painfully Stupid Method Names in Legacy Code: Fix or Leave as Warning?
17 votes

Grep the entire code base for the name of the method. Find out how public it is, how many configs mention it, etc. Rename the method mercilessly (a good IDE can do this), grep again, manually update ...

View answer
Functional Programming: right ideas about concurrency and state?
17 votes

I'll try to hint on the answer. This is not an answer, only an introductory illustration. @jk's answer points to the real thing, zippers. Imagine you have an immutable tree structure. You want to ...

View answer
Binding software to one PC
14 votes

This is an ages-old problem. The only working solution is to make your executable crucially depend on a piece of hardware the user does not control. This is usually either a networked server you ...

View answer
Programming languages that improve your programming skill in general?
14 votes

Don't forget Javascript. It has OO features that are not your usual OO features. It is well-suited for higher-order functions and closures, and you routinely use these. It allows for many functional ...

View answer
Design For Asynchronous User Interface
12 votes

Immediately show some feedback: change the visual state of the button, display an animated throbber. If the app logic allows, disable the button once it has been pressed, enable it back when the ...

View answer
Are Python mixins an anti-pattern?
12 votes

I think mixins can be good, but I also think pylint is right in this case. Disclaimer: opinion-based stuff follows. A good class, mixins included, has one clear responsibility. Ideally, a mixin ...

View answer
1
2 3 4 5
10