You need to make a distinction between the problem itself, and its individual components (objective and constraints).
What is a convex problem?
Consider a generic optimization problem
\begin{align}
(P) \quad \min_{x \in \mathbb{R}^{n}} \quad & f(x)\\
\text{s.t.} \quad & x \in \mathcal{X}
\end{align}
where $\mathcal{X} \subseteq \mathbb{R}^{n}$ .
To settle the terminology: $x$ are the decision variables, $f$ is the objective function, and $x \in \mathcal{X}$ are the constraints.
The problem $P$ is convex if
- $\mathcal{X}$ is a convex set
- $f$ is a convex function, which can be relaxed to "$f$ is convex over $\mathcal{X}$".
For instance:
\begin{align}
\quad \min_{x \in \mathbb{R}} \quad & x^{2}\\
\text{s.t.} \quad & 0 \leq x \leq 1
\end{align}
is a convex problem because $x \rightarrow x^{2}$ is convex and $\{x \in \mathbb{R} | 0 \leq x \leq 1\}$ is a convex set.
On the other hand,
\begin{align}
\quad \min_{x \in \mathbb{R}} \quad & x^{2}\\
\text{s.t.} \quad & x \in \{0, 1\}
\end{align}
is not a convex problem because $\{0, 1\}$ is not a convex set.
Note that in both examples, the objective function is well-defined, continuous, differentiable, and convex.
In the latter case, the non-convexity stems from the constraints, not in the objective.
What about differentiability?
Convexity is a geometric property, which is not tied to differentiability.
For instance, the function $x \rightarrow |x|$ is convex, but it is not differentiable at zero.
Therefore, a problem can be convex even if some of its components are non-differentiable.
For instance:
\begin{align}
\quad \min_{x \in \mathbb{R}} \quad & |x|\\
\text{s.t.} \quad & -1 \leq x \leq 1
\end{align}
is a convex problem.
Differentiability influences the algorithm you can use to solve a problem: some require derivatives, others don't.
For instance, gradient descent or Newton's method require derivatives, and cannot be applied out-of-the-box. The ellipsoid method does not use gradients, and is therefore applicable to convex problems with some non-differentiable components.
Does convexity still matter when we have discrete decisions?
TLDR: Yes, yes and absolutely yes!
You will often encounter in the optimization literature the term "Mixed-Integer XXX Programming", e.g., "Mixed-integer Linear Programming", "Mixed-Integer Convex Programming", etc.
The first part indicates that some variables are restricted to take integer values. The second part usually refers to everything else.
For instance, a Mixed-Integer Linear Programming (MILP) problem is a problem where (i) some variables must be integer and (ii) everything else is linear. For Mixed-Integer Convex Programming (MICP) problems, (i) some variables must be integer and (ii) everything else is convex.
Integrality constraints are non-convex, so mixed-integer problems are not convex.
However, drop the integrality requirements from an MICP problem, and you get a convex problem! This is known as a convex relaxation, and it's the fundamental building block of many optimization algorithms for mixed-integer programming.